How to transform a process into a daemon in Linux / Unix

In this article I will show you how to daemonize processes with nohup, in Linux and Unix.

What is a daemon?

A daemon is a process with no output and input, running independently from the terminal. A daemon dies only when the init process is killed. The important services in Linux are all daemons.

A daemon’s behaviour can be modified from its configuration file. Example /etc/ssh/sshd_config is the configuration file for sshd on Debian (and friends). Like any other process/service in Linux and Unix, you can kill a daemon with kill or pkill.

So, to create a daemon, you have to redirect the stdout and stderr to /dev/null, detach the process from the terminal and make in run in background:

I will daemonize my Firefox. This is usefull because my browser will not close when I logout/close the terminal.

$ nohup firefox& &> /dev/null

Tagged with: , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Subscribe

  

Subscribe to get the latest Linux news and how to guides directly on your e-mail!