Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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.

share|improve this question
up vote 11 down vote accepted

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.

share|improve this answer
Reading again, it's ambiguous whether to OP is exiting the calling shell or not. He only mentions exiting the script, not exiting the shell or the terminal. – Adam Bellaire Sep 9 '09 at 20:06
reading my answer again, you'll notice that I did say "when the shell that runs the script exits". Assuming this shell has its own virtual terminal (not a subshell or something) this is correct. – Kim Sep 9 '09 at 20:29
@Kim: That's true. Your answer is fine, I'm just sure if the OP is closing the calling shell or not. – Adam Bellaire Sep 9 '09 at 20:55

No, the processes should not be killed when the script is finished if you use &. Try it.

knetworkmanager &
emesene &
keepassx &
share|improve this answer

Based on the example programs you gave, it looks like you're trying to start some programs when KDE launches. If so, take a look at KDE's Autostart feature. This article discusses more and gives instructions about how to add programs to autostart.

share|improve this answer
Indeed, that's what I'm trying to do. I fixed it now, thanks. – Bart van Heukelom Sep 9 '09 at 19:52

Adding a '&' after each command will definitely work. It would mean that those scripts or programs would continue to run even after the finishes.

share|improve this answer

Another option would be to start the process as a daemon, using /sbin/start-stop-daemon

share|improve this answer

As others have said, use the & operator to put a command into the background at the time the shell runs it.

If you want the component parts to run in order (rather than concurently), but still want the whole to be backgrounded, use a sub-shell like this:

(knetworkmanager; emesene; keepassx) &

or, if you want to operation of each part to be conditional on the sucessful completetion of the previous part use:

(knetworkmanager && emesene && keepassx) &
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .