Fork system call

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
#include <stdio.h>
#include <unistd.h>

int main ()
  printf("Hello World\n");
  printf("Goodbye Cruel World\n");
this program prints Hello World just once someone please explain

Re: Fork system call

Anuj Kumar wrote:
Quoted text here. Click to load it

Out of topic in Try in comp.unix.programmer.

Hint: "fork();" is after "printf("Hello World\n");"!


Re: Fork system call

Followup-To: comp.unix.programmer

On October 25, 2010 23:22, in, wrote:

Quoted text here. Click to load it

You seem to expect that the program would print "Hello World" more than
once. Why?

Lew Pitcher
Master Codewright & JOAT-in-training   | Registered Linux User #112576
Me: | Just Linux: /
----------      Slackware - Because I know what I'm doing.         ------

Re: Fork system call

Quoted text here. Click to load it

When you create a new process with fork, it does not begin executing from
the beginning of the program; its execution starts after the fork() call.

At the time you printed "Hello World", there was only one copy of the
code running.  You had not called fork yet.

John Gordon                   A is for Amy, who fell down the stairs              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

Site Timeline