P
pat
Hi,
I have a Perl script that basically takes a list of Unix commands and
executes them one by one, does something with the output and goes to
execute the next, some of these commands have to be executed in the
background, the script does not wait for them to finish, just starts it
and keeps going, the problem is that I do need to know if any of the
background processes fail and the return code. I tried using $SIG{CHLD}
but I get a signal for every one of the commands I run, I'm only
interested in the background ones. Is there a way to do a non-blocking
wait on a specific process id?
I use fork to start the process:
if (!defined($pid = fork))
{ # Fork failed
error_message("Couldn't create new process");
return 1;
}
elsif ($pid==0)
{
# Child process block
print "child proccess id is $pid \n";
exec("my_child_command", @args);
}
else
{
# Parent process continues here
print "Copa proccess id is $pid \n";
$status = 0;
# Make sure process started
unless (kill 0 => $pid)
{
print "Background process is not running \n";
return 1;
}
,,,,,,
Any help will be greatly appreciated
Patricia
I have a Perl script that basically takes a list of Unix commands and
executes them one by one, does something with the output and goes to
execute the next, some of these commands have to be executed in the
background, the script does not wait for them to finish, just starts it
and keeps going, the problem is that I do need to know if any of the
background processes fail and the return code. I tried using $SIG{CHLD}
but I get a signal for every one of the commands I run, I'm only
interested in the background ones. Is there a way to do a non-blocking
wait on a specific process id?
I use fork to start the process:
if (!defined($pid = fork))
{ # Fork failed
error_message("Couldn't create new process");
return 1;
}
elsif ($pid==0)
{
# Child process block
print "child proccess id is $pid \n";
exec("my_child_command", @args);
}
else
{
# Parent process continues here
print "Copa proccess id is $pid \n";
$status = 0;
# Make sure process started
unless (kill 0 => $pid)
{
print "Background process is not running \n";
return 1;
}
,,,,,,
Any help will be greatly appreciated
Patricia