How do I code a Mono Daemon How do I code a Mono Daemon linux linux

How do I code a Mono Daemon


To receive notifications in the Unix way, that is using signals, you want to use the Mono.Unix.UnixSignal for each signal that you plan on receiving and then call UnixSignal.WaitAny () on an array of signals.


You would typically do this on a separate thread.


You should implement a service and use mono-service. Google for it and you'll find several examples.


A simple method would be to listen on a (local, high) port and receive commands from a management client, like bind does.

A more unix-ish way would be to register a signal handler using UnixSignal and shutdown properly on receiving a certain signal. See the Mono FAQ, "Can I use signal handlers with Mono?" for caveats and an example.

lupus has found mono-service, which is a hosting process using the ServiceProcess interfaces. Sadly this requires setting MONO_DISABLE_SHM, which disables some features in Mono, in particular cross-process IPC systems.