NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

child process is not created using clone()



Hi,

I have observed one issue with NetBSD-3.1.
The problem description is mentioned below.

Issue:
-------
Not able to create a child process using clone()  if the executable
build by linking with pthread library.

Scenario:
------------

$ cat sample_clone.c

{{{
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <signal.h>

#define ALIGNMENT 0x08

int pid;

int
fun(void *arg)
{
  printf("\n In child \n");
  _exit(0);
}

int  main()
{
  char *ch_stck = NULL,*ch_stck2;
  int status;

  if ((ch_stck = (char *)malloc(10000)) == NULL)
    printf("malloc() fail\n");

  printf("child stack allocated = %x\n",ch_stck);

  ch_stck2 = (void *)((unsigned long)(ch_stck + 10000) & ~(ALIGNMENT -1));

  printf("child stack = %x\n",ch_stck2);

  if ((pid = clone(&fun,ch_stck2,SIGCHLD,NULL)) == -1)
    printf("clone() fail\n");

  if ((wait(&status)) == -1)
    printf("wait() fail\n");

  return 0;
}
}}}


How to reproduce:
--------------------------
# gcc sample_clone.c -o sample_clone -lpthread

# ./sample_clone
{{{
child stack allocated = 804c000
child stack = 804e710
}}}

No child statements printed here.

But the above issue is not observed for static build.

# gcc -static sample_clone.c -o sample_clone -lpthread

# ./sample_clone
{{{
child stack allocated = 8058000
child stack = 8058000

 In child <===== Here child statements printed.
}}}

Please let me know, is this the issue in the NetBSD library ?

Waiting for the reply.

Thank You,
Amol Pise


Home | Main Index | Thread Index | Old Index