[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



[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!