lkml.org 
[lkml]   [1999]   [Feb]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectvfork() from userland
Greetings,

(please cc me on responses as linux-kernel is not forwarding traffic
to me for some undetermined reason).

I have been been playing with the new vfork syscall... it seems that
the child when embarking down the execve syscall road murders its parent.
No doubt I will appear foolish before the world (Linus, may I borrow the
brown paper bag please).

My gut says the solution lies in protecting the parent's stack... but,
I have yet to figure out the bloody thing.

This bit of code behaves as is expected:

#include "/usr/src/linux-2.2.1/include/asm/unistd.h"
#include <stdio.h>

int main (int argc, char **argv)
{
int i=0;
if (!syscall(__NR_vfork)) {
fprintf(stderr,"%d about to exec child\n",getpid(),++i);
_exit(0);
}
fprintf(stderr,"%d parent %d\n",getpid(),i);
}


Here the parent suffers a violent SIGSEGV death:

int i=0;
if (!syscall(__NR_vfork)) {
fprintf(stderr,"%d child %d\n",getpid(),++i);
execlp("echo","echo","I love my parent",0);
}
fprintf(stderr,%d parent %d\n",getpid(),++i);



And now a silly circumvention:

int i=0;
if (!syscall(__NR_vfork)) {
fprintf(stderr,"%d child %d\n",getpid(),++i);
if (!fork())
execlp("echo","echo","I love my parent",0);
_exit(0);
}
fprintf(stderr,%d parent %d\n",getpid(),++i);


What is the obvious gem that I fail to comprehend here?

Reed H. Petty
rhp@draper.net

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:50    [W:0.051 / U:0.936 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site