forking.pl (472 bytes)
1 #!/usr/bin/perl 2 use strict; 3 use warnings; 4 my $ps = `ps -eo pid,cmd | grep monitor\\.pl`; 5 if(!($ps eq '')) { 6 $ps =~ /(^[0-9]+)/; 7 my $pid = $1; 8 print "Monitor already running at pid $pid. Try \$ ps -eo pid,cmd | grep $pid\n"; 9 } else { 10 my $pwd = $ARGV[0]; 11 open my $com, '<', "$pwd/commands.conf"; 12 for(<$com>) { 13 my $f = fork(); 14 if (defined $f) { 15 print; 16 chomp; 17 `$_`; 18 } 19 } 20 while(1){;} 21 }