I wrote my first Daemon and its work correctly. However, all the training materials that I followed are a little different, and I am worried that the steps that I used in the demonstration process may be reordered, and they will work anyway.
The goal is for this daemon to be controlled by init (we are on the old server), so it will be run with root privileges and should give up privileges.
While my order:
- Run syslogger
- Create a file in / var / run, which will become the pid lock file. Change the file permissions for the daemon user. This is done before privileges are removed, in addition, the process will not have access to / var / run.
- Check the box to check if the process is already demonized. This means that if my demonise function is called twice for any reason, it will not try to create another child process.
- Complete the process. Check for errors and exit the parent process.
- Renounce root privileges and become a daemon user.
- Try to open the pid file and get a lock to confirm that there is no other instance of an already running daemon. Then write the current process id to the pid file.
- Get a new session for the child / daemon process.
- Install umask
- Go to the root directory - I think this means that the directory into which the daemon was launched was blocked by the endless daemon process.
- /dev/null - , - , .
- .
- daemonised
, 5 11 . , root, .
, , , . ? , , ?
, , .