« Floats in embedded CSSH to a server running on a non-standard port or different username »

Why should we deamonise a process in Linux?

  08/02/19 18:24, by , Categories: Uncategorized, Linux
Why should we deamonise a process in Linux?

I have never questioned daemonising a Linux program that is a service and has no console UI.

I have just done that as I usually do however now the question has been asked ...

"Why? It adds another layer of complexity, so there should be a reason why" It's a valid question I suppose. How would you have answered ? Here is roughly what I answered ...

Your process becomes its own process group, which is important for job control, scheduling and signals.

It sets the new session for your process group. A Linux process is always tied to a "Terminal". If something happens this terminal it could crash your program or your program could crash the starting terminal.
As we are starting from a start-script you risk killing the init process (PID 1).
One of the reasons of demonizing is to disconnect from the terminal and also to disconnect from the parent process (init). Its a safety thing. Forking is the disconnection part. The I/O needs to be closed before this and/or redirected somewhere. (/dev/null)

init then becomes the parent process. But more needs to be done.

It enables you to change file permissions, creation masks etc. to improve security and also run as a different user other than root. Isolation is one of the foundations of good security.

We chdir() to run the process in a known directory. It's a small point in our system, but still good practice.

If the program crashes it may be hard to restart it as we have not saved the PID and are relying on the process name which may not be unique.
Files etc. may be left open and lock devices. It will make any "Watchdog" process that may need to monitor this service more reliable.

Signals will be for your process only. We are making a service. All POSIX (eg. Linux) services should be demonized.

It's good practice.

 

No feedback yet


Form is loading...

December 2021
Mon Tue Wed Thu Fri Sat Sun
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
 << <   > >>

Search

Random photo

Linux Memory Technology Device mounting by label

  XML Feeds

CMS + email marketing
 

This collection ©2021 by Simon Gaynor

Contact | Help | Blog skins by Asevo | Community CMS