Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

writing a C/C++ daemon (Linux)

I want to write a generic (C/C++) library that I will use to develop daemons in the Linux environment. Rather than reinventing the wheel, I thought I'd come in here to find out if there are any well known libraries in use.

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

As an aside, in terms of library selection criteria, since daemons are pretty 'mission critical' components, it would be much better if the library that you propose is actively maintained by a group of developers (e.g. the BOOST library [again]), has an active community (or at least a mailing list to resort to when faced with tricky situations), rather than a lone individual somewhere out there ...

I saw this document, which is a good starting point, but it is slightly dated, so I'm wondering if there is anything better and more well known/used out there ... ?

BTW, I will be developing on Ubuntu (10.0.4)

like image 998
morpheous Avatar asked Dec 09 '22 14:12

morpheous


2 Answers

An alternative solution is to use a process monitor such as supervisord, which manages multiple services, restarts them when they crash, provides a minimalistic web page to view and control the status of processes, can manage groups of services, supports a general-purpose status-change event forwarding mechanism and other goodies. Such tools give you far more value than a daemon library would.

like image 57
Marcelo Cantos Avatar answered Dec 12 '22 02:12

Marcelo Cantos


#include <unistd.h>

has

int daemon(int nochdir, int noclose);

Which forks, detatches from the controlling terminal, reopens all of {stdin, stdout, stderr} to /dev/null, and changes the working directory to the root directory. (based on flags, of course)

like image 43
nategoose Avatar answered Dec 12 '22 02:12

nategoose