Thursday, February 8, 2024

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

Issue

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.


Solution

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.



Answered By - Mat
Answer Checked By - Pedro (WPSolving Volunteer)