0

I'm trying to run my program as a daemon but the way I am doing it currently requires root access. I was wondering if I could use the nohup command with & to push it to the background instead of running my program as a service.

I know that a similar question has been asked before here: What's the difference between running a program as a daemon and forking it into background with '&'?

but I was wondering if adding the nohup command would make it so it runs like a daemon.

Less
  • 13

1 Answers1

2

There is a difference between running a daemon and running a program in the background -- in fact it is possible to run a daemon in the foreground.

Daemon mode is a different functioning of the software, running in an infinite loop without the user interaction component. Using & doesn't guarantee that the software won't continue to accept input on stdin and output on stdout. Oftentimes, daemon mode has different features, for example software will by default log more thoroughly in daemon mode -- in standard mode, it simply outputs to stdout. Nohup will ignore the output from the software but it still doesn't make the software run in daemon mode. Worst case, there is potential that the software could hang if it is expecting user input.

brirus
  • 36
  • Nice start! Additional bonus for daemon style - you can make a service out of it, and let the systems init manager deal with it as needed. These days this means making a systemd service unit file thingie – ivanivan Aug 30 '18 at 22:43