<p>I'm trying to write a Mono C# daemon for linux.</p>

<p>I'd like to do a starts and stops of it when its done processing instead of just killing the process.</p>

<p>Does anyone have any examples of this?</p>

<p>Edit: I figured out how to use start-stop-daemon --background in debian, so I think I'll just use that for now.</p>

<p>Edit: I'm implementing this in java as well and they have this nice addShutdownHook that catches terminating the app. I need to spend a little more time sorting out the dependencies for mono service, or find a way to catch app termination. </p>

<p>There is the SessionEnd event, but thats only available for services and not console apps</p>

<p><strong>Answer:</strong>
<a href="https://stackoverflow.com/questions/351971/using-mono-service-to-wrap-a-windows-service-on-linux">using mono-service to wrap a windows service on linux</a></p>

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.