PDA

View Full Version : "bg" command not working ?


roparzhhemon
07-29-2007, 02:38 AM
Hello all,

I have a script (called "launch_modem_connection_counter ") that I want to keep on running even after the terminal window in which I launched it has been closed.
The command for this is "bg", but I can't get it to work : if I type the following in a Terminal window,

Urzhiataer-Ewan:~ ewan$ launch_modem_connection_counter
^Z
[1]+ Stopped $LOCATION_FOR_BATH_SCRIPTS/launch_modem_connection_counter.bash_script
Urzhiataer-Ewan:~ ewan$ jobs
[1]+ Stopped $LOCATION_FOR_BATH_SCRIPTS/launch_modem_connection_counter.bash_script
Urzhiataer-Ewan:~ ewan$ bg %1
[1]+ $LOCATION_FOR_BATH_SCRIPTS/launch_modem_connection_counter.bash_script &


and then close that window, when I consult "ps" in a new Terminal window my
process has disappeared ... How should I fix this ?

Ewan





*******************************************************************************************

cpragman
07-29-2007, 05:45 AM
Your bg process remains a "child" of the launching process (Terminal). When you close terminal, it closes the child processes.

To have this process continually running in the background without a terminal window open, I think you'd need to initiate it via launchd or cron (with @boot option). You would need to log your results, because it would not be interactive with the user.

Lutin
07-29-2007, 07:33 AM
Or you can use the screen command.
It allows you to launch a script, then detach it from the terminal.

baf
07-29-2007, 10:26 AM
Some more possibilites:
nohup launch_modem_connection_counter &
This makes sure the command wont get a hup when the shell dies.
Or you could ignore the signal in the script like:
trap "" HUP