#!/usr/bin/perl use warnings; use strict; use Proc::Background; my $arg = shift @ARGV; if (!defined ($arg)) { print ("Usage: \"perl spawn.pl n\" where n is the number of times to spawn\n"); exit (0); } my $c = $arg + 0; print ("Starting PID $$ as instance $c\n"); if ($c > 0) { $c--; sleep (2); if (1) { # # This only works on Windows (as is well noted) # system (1, "perl spawn.pl $c"); } elsif (0) { # # This does not work on Windows because it doesn't have the full path # Same on Linux Mint (Ubuntu or Debian) # my $arg1 = "$c"; # my $command = "perl spawn.pl"; my $command = "spawn.pl"; my $proc1 = Proc::Background->new ($command, $arg1); } elsif (0) { # # Does not work on Windows because it waits for completion # Works on Linux Mint # system ("perl spawn.pl $c &"); } else { # # Need something here # } } sleep (3); print ("PID $$ ended\n"); exit (0);