in reply to how to fork?

If you are checking whether pid is defined, you should do more with it, otherwise you can just say if ($pid=fork)

A fork command can return three possible values:

  1. A positive integer, representing the PID (process ID), in other words, the name of the child. This means that the fork was successful, and you are the parent.
  2. A zero. This means the fork was successful, and you are the child. You can get the name of your parent with the getppid command.
  3. Undefined, which means that the fork failed, and therefore, you are the "parent" (who may have other children, but this attempt failed). When this happens, you can look to see what is in the $! variable to try and figure out what went wrong. Usually, it's because A) You can't fork (e.g. an MS-DOS shell) or B) you have no more processes available. This is a bad thing. Not fatal, but bad. You could sleep and try again (see page 167 of Programming Perl) but best to just 'die' and figure out what's going on.

To further the previous poster's comment, you can not only get rid of the return, but the whole sub as well:

#!/usr/bin/perl $loops = shift || 200; use LWP::Simple qw(get); print "Testing with $loops children...\n"; for ($i=0;$i<$loops;$i++) { if ($pid = fork) { next; } ## Parent gets the credit... if (defined $pid) { ## ...children do the work get("http://www.blahblah.com/blah.php3?xxx"); exit; } else { ## Uh-oh something is really wrong ## The parent is saying this... die "Fork failed at number $i: $!\n"; } }