> Hi Perlers,
> 
> 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 &
>

Shell is considerably different than Perl when it comes to this stuff...
 
> 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 &";

A good figure, though I would expect this to fail, since system blocks,
but maybe not because the shell should be returning control.

> 
> but that invokes the shell, right?  Also, I'd like to capture the
> Process ID of those 3 servers.
> 

Yes it does.

> 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?
> 

In this case you should look at the fork/exec model instead. It allows
you to start a separate process without blocking the parent which you
can then use to do other things while the forked process is running. The
best place to start is with the IPC (InterProcess Communication) docs under,

perldoc perlipc
perldoc -f fork
perldoc -f exec
perldoc -f wait
perldoc -f waitpid

This will cover forking/execing, signals, etc.

> 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.
> 

Sort of, in the case of C<system> the function manages the stuff you are
talking about automatically itself.  In the lower level you will have to
manage it, but the docs listed above should provide enough info to get
you through that.

> Thanks guys and gals,
> 
> --Errin
> 

Per usual this is where I will jump in and suggest POE if you are doing
anything that is not trivial. It makes managing all of this type of
multi-tasking garbage simple.

http://poe.perl.org

HTH,

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to