NetBSD-Users archive

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

Re: child process is not created using clone()



Dear All,

 With further investigation to the above problem, I have analyzed the
process memory maps on netbsd system for my sample scenario.

 The observations are as follows:

 <<Case:1>> Link with pthread:
----------------------------------------------

 % gcc sample_clone.c -lpthread

 % ./a.out
{{{
 child stack allocated = 804c000
child stack = 804e710
}}}

 % pmap -a 5210
 {{{

Start    End         Size  Offset   rwxpc  RWX  I/W/A Dev     Inode - File
08048000-08048fff       4k 00000000 r-xp+ (rwx) 1/0/0 00:00  136709 -
/home/amol/a.out [0xcb3d79dc]
08049000-0805efff      88k 00000000 rw-p- (rwx) 1/0/0 00:00       0 -   [ anon ]
bdb15000-bdb15fff       4k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -   [ anon ]
bdb16000-bdbc1fff     688k 00000000 r-xp+ (rwx) 1/0/0 00:00   68353 -
/lib/libc.so.12.128.2 [0xca6ecbd0]
bdbc2000-bdbc8fff      28k 000ab000 rw-p- (rwx) 1/0/0 00:00   68353 -
/lib/libc.so.12.128.2 [0xca6ecbd0]
bdbc9000-bdbd7fff      60k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -   [ anon ]
bdbd8000-bdbe8fff      68k 00000000 r-xp+ (rwx) 1/0/0 00:00   46223 -
/usr/lib/libpthread.so.0.6 [0xcb48ae70]
bdbe9000-bdbe9fff       4k 00010000 rw-p- (rwx) 1/0/0 00:00   46223 -
/usr/lib/libpthread.so.0.6 [0xcb48ae70]
bdbea000-bdbeafff       4k 00000000 rw-p- (rwx) 1/1/0 00:00       0 -   [ anon ]
bdbeb000-bdbf2fff      32k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -   [ anon ]
bdbf3000-bdbf3fff       4k 00000000 r-xs- (r-x) 0/0/1 00:00       0 -
 [ uvm_aobj ]
bdbf4000-bdbfdfff      40k 00000000 r-xp+ (rwx) 1/0/0 00:00  273409 -
/libexec/ld.elf_so [0xca6ec5e8]
bdbfe000-bdbfefff       4k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -   [ anon ]
bdbff000-bdbfffff       4k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -   [ anon ]
bdc00000-bf9fffff   30720k 00000000 ---p+ (rwx) 1/0/0 00:00       0 -
 [ stack ]
bfa00000-bfa00fff       4k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -
 [ stack ]
bfa01000-bfa01fff       4k 00000000 ---p+ (rwx) 1/0/0 00:00       0 -
 [ stack ]
bfa02000-bfa0ffff      56k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -
 [ stack ]
bfa10000-bfbbffff    1728k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -
 [ stack ]
bfbc0000-bfbcffff      64k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -
 [ stack ]
bfbd0000-bfbeffff     128k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -
 [ stack ]
bfbf0000-bfbfffff      64k 00000000 rw-p- (rwx) 1/0/0 00:00       0 -
 [ stack ]
 total               3076k
}}}

 <<Case:2>> Link without pthread:
--------------------------------------------------

% gcc sample_clone.c

% ./a.out
{{{
child stack allocated = 804b000
child stack = 804d710

 In child
 }}}

 % pmap -a 3156
 {{{
Start    End         Size  Offset   rwxpc  RWX  I/W/A Dev     Inode - File
08048000-08048fff       4k 00000000 r-xp+ (rwx) 1/0/0 00:00  136709 -
/home/amol/a.out [0xcb3d79dc]
08049000-0805dfff      84k 00000000 rw-p- (rwx) 1/0/0 00:00       0 -   [ anon ]
bdb28000-bdb28fff       4k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -   [ anon ]
bdb29000-bdbd4fff     688k 00000000 r-xp+ (rwx) 1/0/0 00:00   68353 -
/lib/libc.so.12.128.2 [0xca6ecbd0]
bdbd5000-bdbdbfff      28k 000ab000 rw-p- (rwx) 1/0/0 00:00   68353 -
/lib/libc.so.12.128.2 [0xca6ecbd0]
bdbdc000-bdbeafff      60k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -   [ anon ]
bdbeb000-bdbf2fff      32k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -   [ anon ]
bdbf3000-bdbf3fff       4k 00000000 r-xs- (r-x) 0/0/1 00:00       0 -
 [ uvm_aobj ]
bdbf4000-bdbfdfff      40k 00000000 r-xp+ (rwx) 1/0/0 00:00  273409 -
/libexec/ld.elf_so [0xca6ec5e8]
bdbfe000-bdbfefff       4k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -   [ anon ]
bdbff000-bdbfffff       4k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -   [ anon ]
bdc00000-bf9fffff   30720k 00000000 ---p+ (rwx) 1/0/0 00:00       0 -
 [ stack ]
bfa00000-bfbeffff    1984k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -
 [ stack ]
bfbf0000-bfbfffff      64k 00000000 rw-p- (rwx) 1/0/0 00:00       0 -
 [ stack ]
 total               3000k
}}}


 <<Case:3>> Link with pthread (static)
--------------------------------------------------------

% gcc -static sample_clone.c -lpthread

% ./a.out
{{{
child stack allocated = 8058000
child stack = 805a710

 In child
 }}}

 % pmap -a 4478
 {{{
Start    End         Size  Offset   rwxpc  RWX  I/W/A Dev     Inode - File
08048000-08052fff      44k 00000000 r-xp+ (rwx) 1/0/0 00:00  136709 -
/home/amol/a.out [0xcb3d79dc]
08053000-08053fff       4k 0000b000 rw-p+ (rwx) 1/0/0 00:00  136709 -
/home/amol/a.out [0xcb3d79dc]
08054000-08054fff       4k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -   [ anon ]
08055000-0806afff      88k 00000000 rw-p- (rwx) 1/0/0 00:00       0 -   [ anon ]
bdbfe000-bdbfefff       4k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -   [ anon ]
bdbff000-bdbfffff       4k 00000000 r-xs- (r-x) 0/0/1 00:00       0 -
 [ uvm_aobj ]
bdc00000-bf9fffff   30720k 00000000 ---p+ (rwx) 1/0/0 00:00       0 -
 [ stack ]
bfa00000-bfbeffff    1984k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -
 [ stack ]
bfbf0000-bfbfffff      64k 00000000 rw-p- (rwx) 1/0/0 00:00       0 -
 [ stack ]
 total               2196k

}}}


 <<Case:4>> If for child stack, instead of dynamicaly allocated memory
used static array then also the issue seen as resolved.

% ./a.out
{{{
array = bfbfedb4

 In child
}}}

% pmap -a 6385
{{{
08048000-08048fff       4k 00000000 r-xp+ (rwx) 1/0/0 00:00  136709 -
/home/amol/a.out [0xcb3d79dc]
08049000-0805efff      88k 00000000 rw-p- (rwx) 1/0/0 00:00       0 -   [ anon ]
bdb15000-bdb15fff       4k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -   [ anon ]
bdb16000-bdbc1fff     688k 00000000 r-xp+ (rwx) 1/0/0 00:00   68353 -
/lib/libc.so.12.128.2 [0xca6ecbd0]
bdbc2000-bdbc8fff      28k 000ab000 rw-p- (rwx) 1/0/0 00:00   68353 -
/lib/libc.so.12.128.2 [0xca6ecbd0]
bdbc9000-bdbd7fff      60k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -   [ anon ]
bdbd8000-bdbe8fff      68k 00000000 r-xp+ (rwx) 1/0/0 00:00   46223 -
/usr/lib/libpthread.so.0.6 [0xcb48ae70]
bdbe9000-bdbe9fff       4k 00010000 rw-p- (rwx) 1/0/0 00:00   46223 -
/usr/lib/libpthread.so.0.6 [0xcb48ae70]
bdbea000-bdbeafff       4k 00000000 rw-p- (rwx) 1/1/0 00:00       0 -   [ anon ]
bdbeb000-bdbf2fff      32k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -   [ anon ]
bdbf3000-bdbf3fff       4k 00000000 r-xs- (r-x) 0/0/1 00:00       0 -
 [ uvm_aobj ]
bdbf4000-bdbfdfff      40k 00000000 r-xp+ (rwx) 1/0/0 00:00  273409 -
/libexec/ld.elf_so [0xca6ec5e8]
bdbfe000-bdbfefff       4k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -   [ anon ]
bdbff000-bdbfffff       4k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -   [ anon ]
bdc00000-bf9fffff   30720k 00000000 ---p+ (rwx) 1/0/0 00:00       0 -
 [ stack ]
bfa00000-bfa00fff       4k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -
 [ stack ]
bfa01000-bfa01fff       4k 00000000 ---p+ (rwx) 1/0/0 00:00       0 -
 [ stack ]
bfa02000-bfa0ffff      56k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -
 [ stack ]
bfa10000-bfbbffff    1728k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -
 [ stack ]
bfbc0000-bfbcffff      64k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -
 [ stack ]
bfbd0000-bfbeffff     128k 00000000 rw-p+ (rwx) 1/0/0 00:00       0 -
 [ stack ]
bfbf0000-bfbfffff      64k 00000000 rw-p- (rwx) 1/0/0 00:00       0 -
 [ stack ]

}}}

From the above observation it seems that, The dynamicaly allocated
memory for the child stack having the issue on the NetBSD system.

I appreciate your valuable inputs for this issue.
Please help me in this regards.

Thank You,
Amol Pise



On Tue, Apr 12, 2011 at 3:04 PM, amol pise <amolpise15%gmail.com@localhost> 
wrote:
> 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