start-stop-daemon with --background vs running using & option

2.5k views Asked by At

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

There are 2 answers

4
tim1724 On BEST ANSWER

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.

0
Mark On

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.