Skip to content

libμdaemon is a small C/C++ library to make writing Unix daemons simple

License

Notifications You must be signed in to change notification settings

geoherna/libudaemon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libμdaemon

A small C/C++ library to make writing Unix daemons simple

Building

libμdaemon is standalone, you don't need to link it with anything strange or download a tar file and stick it in the source directory, if you have a decent unix-like system, FreeBSD, Arch Linux, for example, CMake, and a decent compiler then you can build the library.

$ git clone https://github.com/xampp/libudaemon.git
$ cd libudaemon
$ mkdir build
$ cd !$ && cmake ../
$ make && sudo make install

Example

#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <udaemon.h>

int main(int argc, char* argv[]) {
	// We need options damn it!~
	lud_opt opts = {
		true,				// Use syslog
		"udaemonTest",		// The daemon name
		"/tmp/udtest.lwk",	// The lock file location
		"/tmp/udtest.pid",	// The PID file location
		NULL,				// The user to switch to
		NULL				// The working dir to switch to
	};
	// Ensure we daemonize correctly
	int err;
	if((err = lud_daemonize(&opts)) < 0) {
		printf("libudaemon error: %d (%s)", err, lud_strerror(err));
		exit(err);
	}

	// DO WORK
	syslog(LOG_INFO, "A scary daemon!");

	lud_status* stat = lud_querystatus();
	syslog(LOG_INFO, "PID: %d PPID: %d SID: %d", stat->pid, stat->ppid, stat->sid);

	// Job's done
	lud_cleanup();
	return err;
}

License

libμdaemon is licensed under the BSD 3-clause license, see LICENSE.md

About

libμdaemon is a small C/C++ library to make writing Unix daemons simple

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages