4

I'm searching the "getpid" function in the kernel, however i could not find the actual function.

It should be something like this:

asmlinkage long sys_getpid(void)
{
return current-> tgetid;
}

All I can find is system call tables, not the actual implementation of this system call.

Kernel version is: 3.0.20

Thanks in advance.

Onur Senture
  • 519
  • 5
  • 16

1 Answers1

7

The actual definition is in kernel/timer.c:

/**
 * sys_getpid - return the thread group id of the current process
 *
 * Note, despite the name, this returns the tgid not the pid.  The tgid and
 * the pid are identical unless CLONE_THREAD was specified on clone() in
 * which case the tgid is the same in all threads of the same group.
 *
 * This is SMP safe as current->tgid does not change.
 */
SYSCALL_DEFINE0(getpid)
{
    return task_tgid_vnr(current);
}

task_tgid_vnr is a static inline in include/linux/sched.h.

Mat
  • 202,337
  • 40
  • 393
  • 406
  • Sorry, but i'm still having trouble to find this file. There are lots of timer.c in different directories (arch) . Which one do i need to look at it? – Onur Senture Feb 18 '12 at 12:44
  • `kernel_source_dir/kernel/timer.c`, as said above. – Mat Feb 18 '12 at 12:49
  • there is no such directory in the root directory of kernel_source_dir in kernel 3.0.20. i have also 2.6.32.56 and i can see this timer.c file in the directory you said, but again i could not find such directory named kernel in the root in 3.0.20. – Onur Senture Feb 18 '12 at 13:34
  • There is such a directory in the following versions at least: linux-3.0.3-gentoo/kernel/timer.c linux-3.1.0-gentoo/kernel/timer.c linux-3.1.4-gentoo/kernel/timer.c linux-3.1.5-gentoo/kernel/timer.c linux-3.1.6-gentoo/kernel/timer.c linux-3.2.1-gentoo/kernel/timer.c linux-3.2.5-gentoo/kernel/timer.c - I believe it is also present in all 2.6 releases. Please make sure you have a full kernel source extract. You can also see the source online e.g. here: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=tree – Mat Feb 18 '12 at 14:26
  • Thank you Mat, I think that the kernel that i have, had some missing directories. – Onur Senture Feb 18 '12 at 16:10