lkml.org 
[lkml]   [2004]   [Jun]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectclone() <-> getpid() bug in 2.6?

I have a test program (see attached) that shows what looks like a bug in
2.6.5-1.358 (FedoraCore2)...and breaks my program :(

In summary, I am doing:

clone(run_thread, stack + sizeof(stack) -1,
CLONE_FS|CLONE_FILES|CLONE_VM|SIGCHLD, NULL))

According to the man page the child process should have its own pid as
returned by getpid()...much like fork().

In 2.6 the child receives the parent's pid from getpid(), while 2.4
works as documented:

In 2.4 the test program does:
parent pid: 26647
clone returned pid: 26648
thread reported pid: 26648

In 2.6 the test program does:
parent pid: 16665
thread reported pid: 16665
clone returned pid: 16666

Is this fixed in later kernels?

Thx

Russ

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sched.h>
#include <signal.h>
#include <sys/wait.h>

/* to compile:
gcc -Wall clone-pid-test.c -o clone-pid-test
*/

static int run_thread(void *arg)
{
printf("thread reported pid: %d\n", getpid());

return 0;
}

static char stack[4096];

static int create_thread()
{
int
pid;

/* create thread */
if ( (pid = clone(run_thread, stack + sizeof(stack) -1,
CLONE_FS|CLONE_FILES|CLONE_VM|SIGCHLD, NULL)) == -1 ) {
perror("clone:");
exit(-1);
}/* end if */

return pid ;
}

int main(int argc, char *argv[])
{
printf("parent pid: %d\n", getpid());
printf("clone returned pid: %d\n", create_thread());
wait(NULL);
return 0;
}
\
 
 \ /
  Last update: 2005-03-22 14:03    [W:0.085 / U:0.592 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site