Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where the system call function “sys_getpid” is located in the linux kernel?

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.

like image 515
Onur Senture Avatar asked Sep 17 '25 23:09

Onur Senture


1 Answers

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.

like image 139
Mat Avatar answered Sep 21 '25 10:09

Mat