Linux – How to Start a Process in the Background

linuxshell-script

I'm trying to create a script which starts some programs

startup.sh

knetworkmanager
emesene
keepassx

The problem is that when I run the script, it only starts knetworkmanager. This is because it'll start it, then wait until it's finished. How can I start a program without waiting for it? I don't think I can just add "&" after each command, because all processes will still be killed when the script is finished.

Best Answer

When the shell that runs the script exits, it send a HUP signal to the processes you started. If those don't catch the signal, they will terminate. So whether just using & is sufficient depends on the application. To be safe, use nohup like that:

nohup your-program >>/dev/null 2>>/dev/null &

See the man pages for nohup and kill for more details or read the wikipedia article about nohup.

Related Question