[Mono-dev] Writing a cross platform daemon in C#

Miguel de Icaza miguel at novell.com
Fri Jan 8 15:56:45 EST 2010


> Does anyone have any examples of (or can point me to easy to understand
> examples of) daemons in C# and port monitoring in C#?

A daemon is merely a program that is not connected to a terminal or a
GUI.   All you need to do to launch a program as a daemon is to launch
it in the background either from a startup script on your system, or by
calling Mono like this:

	nohup mono program.exe &

Since daemons typically can not reliably log data to stdout/stderr, they
tend to write their data using syslog so the data ends up in a system
managed log, or even better, they dump the data in a well known
location, like this:

	nohup mono daemon.exe /home/logs/mylogs &

Or you can dump the data in a database (this might be a better idea).

Additionally, daemons ideally can be controlled remotely, the operations
on Linux are usually pretty trivial and are based on hooking up to
signals to receive very simple messages.   Usually the message means
"Relaod your configuration" or "Shut down propertly".

In this day and age, you might be better off just controlling your
daemon using a tiny protocol.   You could listen on a socket on a well
known port, and send command there, or if you are feeling Web two point
ohish, you can start an HttpListener and control your daemon by
navigating to http://localhost:YOURPORT/ and issuing commands there.


More information about the Mono-devel-list mailing list