[Omaha.pm] fork() only goes 2 procs at a time?

Jay Hannah jhannah at omnihotels.com
Wed Feb 22 09:55:42 PST 2006


[I'm currently chasing this on IRC. If anyone wants to beat them to it,
please do!]

I expected this code to go through 1..10 immediately and exit, each
child hanging around for 1 second. But it doesn't. It goes slowly, only
launching 2 at a time. Why?

-------------------
#!/usr/bin/perl

use IO::Handle;
STDOUT->autoflush(1);

for (1..10) {
   print "launch $_\n";
   if ($pid = open ($child, "-|")) {
      # Parent code here...
   } else {
      # Child code here...
      die "cannot fork: $!" unless defined $pid;
      `sleep 1`;
      exit;
   }
}
-------------------

(I'm trying to do super-quick/easy command line load testing of various
commands on Linux.)

Thanks!


More information about the Omaha-pm mailing list