public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* clone() <-> getpid() bug in 2.6?
@ 2004-06-05 15:28 Russell Leighton
  2004-06-05 20:45 ` Linus Torvalds
  0 siblings, 1 reply; 54+ messages in thread
From: Russell Leighton @ 2004-06-05 15:28 UTC (permalink / raw)
  To: linux-kernel

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


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

[-- Attachment #2: clone-pid-test.c --]
[-- Type: text/plain, Size: 733 bytes --]


#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;
}

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

end of thread, other threads:[~2004-06-12 13:48 UTC | newest]

Thread overview: 54+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-05 15:28 clone() <-> getpid() bug in 2.6? Russell Leighton
2004-06-05 20:45 ` Linus Torvalds
2004-06-05 20:55   ` Arjan van de Ven
2004-06-05 21:13     ` Linus Torvalds
2004-06-05 21:48       ` Robert Love
2004-06-05 22:44         ` Linus Torvalds
2004-06-05 21:53     ` Chris Wedgwood
2004-06-05 22:47       ` Robert Love
2004-06-05 22:57         ` David S. Miller
2004-06-05 23:01         ` Linus Torvalds
2004-06-05 23:07         ` Davide Libenzi
2004-06-05 23:18           ` Linus Torvalds
2004-06-05 23:26             ` Davide Libenzi
2004-06-06  5:08             ` Kalin KOZHUHAROV
2004-06-06  5:13               ` Chris Wedgwood
2004-06-06  5:34                 ` Kalin KOZHUHAROV
2004-06-06  6:07               ` Linus Torvalds
2004-06-06  6:43                 ` Kalin KOZHUHAROV
2004-06-06  7:57                 ` Erik Andersen
2004-06-06 16:57                   ` Linus Torvalds
2004-06-06 18:53                     ` Simon Kirby
2004-06-06 19:00                       ` Linus Torvalds
2004-06-06  9:52                 ` Bernd Eckenfels
2004-06-06 13:07                   ` Paul Rolland
2004-06-06 17:20                     ` Patrick J. LoPresti
2004-06-06 17:31                       ` Paul Rolland
2004-06-06 17:43                       ` Davide Libenzi
2004-06-06 18:17                       ` Rik van Riel
2004-06-06 18:37                         ` Patrick J. LoPresti
2004-06-06 16:33                 ` chris
     [not found]                 ` <200406062022.54320.vda@port.imtp.ilyichevsk.odessa.ua>
2004-06-06 17:55                   ` Linus Torvalds
2004-06-07 18:20                 ` Bruce Guenter
2004-06-08 11:06                   ` Kalin KOZHUHAROV
2004-06-05 23:19           ` Robert Love
2004-06-06 14:29   ` Russell Leighton
2004-06-06 15:38     ` Using getpid() often, another way? [was Re: clone() <-> getpid() bug in 2.6?] Russell Leighton
2004-06-06 15:44       ` Robert Love
2004-06-07  0:20         ` Russell Leighton
2004-06-06 15:58       ` Arjan van de Ven
2004-06-06 23:49         ` Russell Leighton
2004-06-07 12:13           ` Arjan van de Ven
2004-06-07 13:48             ` Sean Neakums
2004-06-07 14:00               ` Christoph Hellwig
2004-06-07 14:10                 ` Sean Neakums
2004-06-07 18:42                 ` David Mosberger
2004-06-07 23:02                   ` Russell Leighton
2004-06-07 23:27                     ` David Mosberger
2004-06-08  6:01                     ` Arjan van de Ven
2004-06-08  9:48                       ` Eric W. Biederman
2004-06-07  0:09         ` Russell Leighton
2004-06-07 12:20           ` Arjan van de Ven
2004-06-06 17:19       ` Linus Torvalds
2004-06-12  9:15         ` Dominik Straßer
2004-06-12 13:47           ` Linus Torvalds

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