Recording the C / C ++ daemon (Linux)

I want to write a common (C / C ++) library that I will use to create daemons in a Linux environment. Instead of reinventing the wheel, I thought I would come here to find out if there are any known libraries in use.

The library can be either C or C ++ - although I would prefer C ++ (perhaps something that was part of, or based on an excellent BOOST library?).

Alternatively, in terms of library selection criteria, since daemons are rather β€œcritical” components, it would be much better if the library you are offering is actively supported by a development team (for example, the BOOST library [again]), has an active community (or at least a mailing list resorted to in difficult situations), and not a lonely person somewhere out there ...

I saw this document , which is a good starting point, but it is slightly outdated, so I wonder if there is anything better and more well known / used there ...?

By the way, I will develop on Ubuntu (10.0.4)

+4
source share
3 answers

An alternative solution is to use a process monitor, such as supervisord , which manages several services, restarts them when they fail, provides a minimalistic web page for viewing and monitoring the status of processes, managing service groups, supporting a mechanism for forwarding general-purpose change events and other positive effects. Such tools give you much more value than the demon library.

+7
source
#include <unistd.h> 

It has

 int daemon(int nochdir, int noclose); 

Which forks, exits from the control terminal, open all {stdin, stdout, stderr} in / dev / null again and change the working directory to the root directory. (based on flags of course)

+6
source

If your daemon uses tcp / ip sockets, you can use inet daemon (or xinetd). However, your process starts as a new incoming connection arrives. However, scalability issues may arise in the event of a large-scale deployment.

+1
source

Source: https://habr.com/ru/post/1316645/


All Articles