Subject: Re: fork()
From: [email-masked] (Wade Richards)

20 Nov 1996 23:03:30 -0800
Sender: [email-masked]
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
X-Sender: [email-masked]
X-Mailer: Windows Eudora Light Version 1.5.4 (32)
Original-To: Fabricio Chalub <[email-masked]>
Original-Cc: [email-masked]
Original-Sender: [email-masked]

At 19:29 20/11/96 -0300, Fabricio Chalub wrote:
}This simple program:
}main () {
}  fork();
}  printf("Hi");
}}
[ fails...]

I tried your program, and noticed that it would sometimes work, and
sometimes fail.  Looking a bit harder, I noticed that it seems only to blow
up if the original process exits before the child process.  For example:

main () {
  int pid = fork();
  printf("after fork\n" );
  if (pid) sleep(1);
}

This program always works, and if you change the (pid) to (!pid), it always
fails.  For a work-around, you can always wait for the child process before
exiting the main process:

main () {
  int s, p = fork();
  printf("Hi\n" );
  if (p) waitpid(p,&s,0);
}

        --- Wade
----------
Wade Richards    -= [email-masked] =- 
"Never attribute to malice what can adequately be explained by stupidity."

-
For help on using this list, send a message to
"[email-masked]" with one line of text: "help".