Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
7
rated 0 times [  7] [ 0]  / answers: 1 / hits: 13890  / 2 Years ago, tue, april 19, 2022, 6:25:35

I had a FreeBSD machine and it had a /usr/sbin/daemon command which could run my program in the background.



The question is how to do something similar in Ubuntu? I would like something I can put in a startup script.

What I mean is my program can't put itself in a background when starts.



I tried:



start-stop-daemon --start --quiet --pidfile $PIDSPATH/$PIDFILE --exec $DAEMON


But it just starts the program and I must wait for it to finish.


More From » services

 Answers
4

Use the --background option of start-stop-daemon. From the manual page of start-stop-daemon(8):




-b, --background

Typically used with programs that don't detach on their own.
This option will force start-stop-daemon to fork before starting the
process, and force it into the background. WARNING: start-stop-daemon
cannot check the exit status if the process fails to execute for
any reason. This is a last resort, and is only meant for programs
that either make no sense forking on their own, or where it's not
feasible to add the code for them to do this themselves.




In a shell, programs can be backgrounded with & as in:



$ myprogram &
[1] 5042

[#40203] Wednesday, April 20, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ilityushing

Total Points: 18
Total Questions: 100
Total Answers: 113

Location: Senegal
Member since Wed, May 13, 2020
4 Years ago
;