Sunday, 14 December 2014

Daemon Process in short

I have compiled this post to give an overview of what a daemon process is.

A daemon is a background process that is designed to work without user intervention. It does not have a terminal (being background). Usually daemon names end with a 'd' but that is not a restriction. A daemon process waits for an event to occur or some condition to be met. To delve in further, it is necessary to know what a process identifier or process ID or PID is. On a Unix like operating system, a PID is a identification number is a unique, non-negative number assigned to each active process. PIDs are generally large numbers like 7732 , 4483 but this does not mean that there are so many processes running on the system. It is so because PIDs are not immediately reused for preventing possible errors. You can test it immediately, by opening shell and typing in ps. If that is a new shell, it will show only 2 processes i.e bash and ps and generally the PID will be a large number.

Now, there is one special process called init. This is always the first process to be initiated when the system boots and it remain as long as the system is on. It is assigned a PID 1. This means every process will have init in its process hierarchy. The parent process of a daemon is mostly init (PID 1) but this is not always true, specially when you launch a daemon process using terminal. You can test it when you create a daemon and use the following command to get its PPID i.e parent's PID  as given here .
ps -o ppid= <pid>

It won't necessarily be 1. 

You can know what process corresponds to a given pid by ps -j pid . So you can verify if it holds true for init.

Here is an important question that i asked regarding killing of daemon process http://codereview.stackexchange.com/questions/73613/monitor-downloads-folder-and-sort-files-as-they-are-downloaded

Compiled from
1. http://www.linfo.org/daemon.html
2. http://en.wikipedia.org/wiki/Daemon_(computing)
3. http://askubuntu.com/questions/153976/how-do-i-get-the-parent-process-id-of-a-given-child-process
4. http://www.linfo.org/pid.html


                          

No comments:

Post a Comment