So when I run this code it seems to fork bomb the system can you guys help me out? All I want to do is start a thread for each one of the appWatch domains and enviroments.
#!/usr/bin/perl
#
#
# Starts the mass processes to watch each directory & enviroment.
#
#
#
###################################################################################
use strict;
use warnings;
use POSIX 'setsid';
setsid();
my @domains = (qw(austin batman luke heman drevil joker skeltor drevil goodguy badguy));
my @envs = (qw(qa dev));
foreach my $env (@envs){
foreach my $guy (@domains){
unless(my $pid = fork()){
system("echo $env.$guy");
system("sleep 10 ");
#system("./appWatch -d $guy -e $env");
open PID, ">>pid.lock";
print PID $$ . "\n";
print "$$ is Parent, $pid is child";
}
}
}
wait();
Your code should only create three children. If you are seeing a bunch of children being created then you are running different code (or the culprit is
appWatchnot your code). On a slightly unrelated note, there are a couple things you should probably be doing differently:forkhas three possible return values, not twoexecinstead of system if you don’t want to return to the codesystemandexecinstead of the one argument version if you don’t want the shell to do stuff with the arguments.Here is my version of your code:
You updated version of the code shows what happened. Your child does not exit. Here is how I would write your code: