#!/bin/perl
# File: fork2

# Demonstrate a parent creating a child who finishes after the parent.

# Call fork to create a child process
if (fork == 0) {   # Child branch
   print "I am the child. I will sleep a couple seconds.\n";
   sleep(2);
   print "I am the child and I'm gone.\n";
   exit(0);        # End of child
}
else {             # Parent branch
   print "I am the parent, and I'm exiting now.\n";
   # system("ps -f");   # UNCOMMENT THIS LINE
}  # End of parent
