public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* PROBLEM: getpid() returning same value as getppid()
@ 2010-05-26 14:45 Sébastien Paumier
  2010-05-26 15:16 ` Nick Bowler
  0 siblings, 1 reply; 3+ messages in thread
From: Sébastien Paumier @ 2010-05-26 14:45 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 311 bytes --]

Hi,
here is a bug that occurs on my kernel 2.6.31-21, maybe with older ones. 
  If a C program contains a function with the constructor attribute that 
calls getpid(), then, a call to syscall(SYS_fork) produces a son that 
obtains the same value calling getpid() or getppid().

Best regards,
Sébastien Paumier

[-- Attachment #2: test.c --]
[-- Type: text/x-csrc, Size: 510 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>

void foo(void) __attribute__ ((constructor));

void foo(void) {
	/* Removing this call to getpid() removes the bug */
	getpid();
}


int main(void){
	int i=syscall(SYS_fork);
	if (0==i) 
		/* Big problem: the son prints the same value for getpid() and getppid() */
		printf("__son : %d   father : %d__\n", getpid(), getppid());
	else
		printf("<<father : %d   son : %d>>\n", getpid(), i);
	return 0;
}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-06-02 15:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-26 14:45 PROBLEM: getpid() returning same value as getppid() Sébastien Paumier
2010-05-26 15:16 ` Nick Bowler
2010-06-02 15:02   ` Michal Hocko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox