Hi Perlers,
Hello,
I know that questions like this get asked all the time, but I guess it's just my turn to ask 'em!
I need to kick of some processes in my script. However, the script needs to kick them all off at once and then stick around to do some other things. I'm kinda new to Perl, but in my OS's shell, I'd do this (actually, I DO do this ... this Perl script will be replacing this shell script):
#!/bin/sh nohup /path/to/process/one/bin/server.sh >/dev/null 2>&1 & nohup /path/to/process/two/bin/server.sh >/dev/null 2>&1 & nohup /path/to/process/three/bin/server.sh >/dev/null 2>&1 &
I figure I can pass that string directly to system() in Perl,
system "nohup /path/to/process/one/bin/server.sh >/dev/null 2>&1 &"; system "nohup /path/to/process/two/bin/server.sh >/dev/null 2>&1 &"; system "nohup /path/to/process/three/bin/server.sh >/dev/null 2>&1 &";
but that invokes the shell, right? Also, I'd like to capture the Process ID of those 3 servers.
So I tried the above and it works, but I'd still like to be able to leave the shell out of this. And what about those process IDs?
One last question. If I do the above, does the OS consider those 3 servers my scripts "children"? I know that comes with some responsibility (I've been looking at some things about the SIGCHLD signals). oh, and btw, this is Solaris I'm talking about here.
The perlipc man page has a lot of information on how to run a child process and how to capture/ignore signals like HUP.
perldoc perlipc
This might do what you want (UNTESTED!)
my @children; for my $server ( </path/to/process/*/bin/server.sh> ) { local $SIG{ HUP } = 'IGNORE'; defined( my $pid = fork ) or die "Cannot fork: $!"; unless ( $pid ) { # in child open STDOUT, '>', '/dev/null' or die $!; open STDERR, '>', '/dev/null' or die $!;
exec $server or die "Cannot exec $server: $!"; } push @children, $pid; }
John -- use Perl; program fulfillment
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>