Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Keep a "system" process running if script is prematurely exited?

by sflitman (Hermit)
on Jun 17, 2010 at 05:44 UTC ( [id://845145]=note: print w/replies, xml ) Need Help??


in reply to Keep a "system" process running if script is prematurely exited?

Under bash, you can use the disown command to detach it from the process and make it owned by the top-level process init. From bash:
# gedit & # disown $!
Where $! is the last process id. To do this in Perl, I tried this:
# perl -e 'system q{gedit &}'
It starts gedit in its own window on my Ubuntu system and returns to the shell prompt. Then I close the terminal, and voila! gedit is still running. Can anyone tell us why disown is not needed in this case?

HTH,
SSF

Replies are listed 'Best First'.
Re^2: Keep a "system" process running if script is prematurely exited?
by cdarke (Prior) on Jun 17, 2010 at 07:54 UTC
    Probably because bash shell option huponexit is set to off (see shopt for option settings).
    By the way, disown -h will supress HUP for a specific job, see help disown
Re^2: Keep a "system" process running if script is prematurely exited?
by Anonymous Monk on Jun 17, 2010 at 06:32 UTC
    Probably because the perl process that launched gedit is finished (isn't connected to the shell anymore ie STDIN/STDOUT/STDERR are closed)

    You can confirm by comparing strace/truss output with

    perl -e 'system q{gedit &} scalar <>;'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://845145]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-29 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found