What is the difference in running a process in background using start-stop-daemon with --background option and using with &?Which option is best and why?
2 Answers
If you use start-stop-daemon --background
then start-stop-daemon will fork off a process to run in the background and then start-stop-daemon immediately exits. Among other things this means you can check the exit status of start-stop-daemon.
If you use start-stop-daemon &
then the shell forks off a background process and runs start-stop-daemon in it. You won't be able to check its exit status as it won't actually exit (until the thing it runs exits).
In most cases start-stop-daemon --background
is a better choice.

- 126
- 5
-
i still don't have much clarity on what makes start-stop-daemon --background better option than & . – Prasad Roy Aug 06 '20 at 02:57
-
Are you running it directly on the command line or are you using it in a script (e.g., a startup script)? If you're running it on the command line it doesn't make a lot of difference unless you want to leave it running even after you exit the shell. In that case start-stop-daemon will do the necessary work to make sure the daemon stays running in the background after the shell exits. if you use & then you need to take other steps (e.g., nohup) – tim1724 Aug 07 '20 at 02:34
-
In a startup script you probably want to have start-stop-daemon do things like create a pidfile and stuff. And you want start-stop-daemon to be able to kill the process when things shut down. That all works more reliably if you use --background. – tim1724 Aug 07 '20 at 02:37
-
I am using it in startup script with --background option. – Prasad Roy Aug 08 '20 at 03:13
I prefer the &
option for making a background job. However, on the occasions that I forget to include the &
, I use the Ctrl-Z command to stop the job and then enter bg
to move the stopped command into the background.
While I have not observed any difference in the approaches (with the exception that &
can be used in a script). A colleague of mine was very pleased to find out about the Ctrl-Z option of suspending a job. He claimed that he had some tasks where that "worked better".
If you want to learn more about Ctrl-Z and bg
, look for bash job control.

- 4,249
- 1
- 18
- 27