Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a script which starts a number of background processes and if works fine when called from the cmdline.

However the same script is also called during my xsession startup and additionally on some udev events. In both cases the background processes disappear.

I had put a sleep 10 into the script and I could see, that the bg processes are indeed started, but once the script exists it takes the bg processes with it. I tried to solve with by invoking the bg processes with start_stop_deamon --background, but this does not make a difference. Hoever, I can invoke the script from a console and exit the session and the bg processes are still running.

Other than fixing my immediate problem (though any help would be much appreciated), I am keen to understand the logic behind it all. I suspect something related to the absence of a terminal.

share|improve this question
You may attach with strace -p $PID to one such background process so you will see why it exits (which signal it gets). – Hauke Laging Apr 29 at 20:18

1 Answer

up vote 1 down vote accepted

Protect your processes with nohup:

nohup command-name &

You can also use this technique if you want to ignore stdout and stderr redirection to nohup.out:

command-name & disown
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.