bug in sys_getpid() comment?
this is sys_getpid() on 2.4.19
asmlinkage long sys_getpid(void)
{
/* This is SMP safe - current->pid doesn't change */
return current->tgid;
}I assume we are returning tgid so that no matter what thread of a multithreaded program calls getpid we return the same value, and that the comment with pid is old and should have been updated when it was changed to return tgid. A student in my Operating Systems class pointed this out, so I figured no harm in pointing the possible bug out.
thanks,
shaya
Quoted 11 lines · Shaya Potter
asmlinkage long
sys_getpid(void){ /* This is SMP safe - current->pid doesn't change */ return current->tgid; }I assume we are returning tgid so that no matter what thread of a multithreaded program calls getpid we return the same value, and that the comment with pid is old and should have been updated when it was changed to return tgid. A student in my Operating Systems class pointed this out, so I figured no harm in pointing the possible bug out.
Yes, you are correct, the comment is wrong. We switched to returning the tgid in early 2.4 when CLONE_THREAD was introduced. The tgid and pid are identical unless CLONE_THREAD was used.
Attached patch fixes the typo and adds some comments explaining this. Marcelo, patch is against 2.4.20-pre8, please apply.
Robert Love
kernel/timer.c +10 -2
@@ -740,10 +740,18 @@* The Alpha uses getxpid, getxuid, and getxgid instead. Maybe this * should be moved into arch/i386 instead? */ - + +/** +* 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. +*/ asmlinkage long sys_getpid (void ) { -/* This is SMP safe - current->pid doesn't change */ return current->tgid; }