<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body dir="ltr" bgcolor="#ffffff" text="#000000">
Hi all,<br>
<br>
Here is fork.c in its entirety:<br>
<blockquote type="cite">#define _GNU_SOURCE<br>
#include <sys/types.h><br>
#include <unistd.h><br>
#include <sched.h><br>
#include <sys/syscall.h><br>
#include <signal.h><br>
<br>
#include <stdio.h><br>
<br>
int main()<br>
{<br>
pid_t child;<br>
<br>
printf("Started, pid=%d\n", getpid() );<br>
<br>
//child=fork();<br>
child=vfork();<br>
//child=syscall(__NR_fork);<br>
//child=syscall(__NR_vfork);<br>
//child=syscall(__NR_clone, CLONE_VFORK|SIGCHLD, 0);<br>
<br>
if( child<0 ) {<br>
perror("fork failed");<br>
<br>
return 1;<br>
}<br>
<br>
if( child==0 ) {<br>
printf("Child, pid=%d\n", getpid() );<br>
} else {<br>
printf("Parent, child=%d\n", child );<br>
<br>
int status;<br>
wait(&status);<br>
}<br>
<br>
return 0;<br>
}<br>
</blockquote>
I compile it with gcc 4.3.2 from Debian Lenny with the following
command line:<br>
gcc -O0 -g -o fork fork.c<br>
<br>
When I run it, I get:<br>
<blockquote type="cite">$ ./fork<br>
Started, pid=13711<br>
Child, pid=13712<br>
Parent, child=13712<br>
Segmentation fault<br>
</blockquote>
<br>
The core dump is of no use whats o' ever - it shows an rip of 0. If the
program is run from within strace, there is no segmentation fault. Same
goes if it is being run by gdb or valgrind. In fact, I'm having a
somewhat difficult time deciding whether it is the parent or the child
that dumps core! (adding a printf after the "wait" confirms that the
child returned with status code 0, so it must be the parent that is seg
faulting).<br>
<br>
help?<br>
<br>
Shachar<br>
<pre class="moz-signature" cols="72">--
Shachar Shemesh
Lingnu Open Source Consulting Ltd.
<a class="moz-txt-link-freetext" href="http://www.lingnu.com">http://www.lingnu.com</a>
</pre>
</body>
</html>