KaisarCode

dmn.c

dmn.c - IPC Daemon Manager

dmn.c provides a small C library and CLI for daemonizing named application processes behind local IPC endpoints. Applications can register a command under a name, keep it resident, relay stdin/stdout through it, list active registrations, remove them, and dispatch signals to managed processes.

On POSIX, dmn.c uses Unix Domain Sockets and signals (kill). On Windows, it uses Named Pipes and named kernel events (CreateEvent/SetEvent). The CLI keeps the direct named-runtime workflow and is implemented on top of libdmn.


CLI

Examples

Start or update a daemon:

dmn mydaemon /bin/cat

Relay stdin to a daemon:

printf 'hello\n' | dmn mydaemon

Resident backends keep their process state across relays. A backend may emit EOT (ASCII 4) to mark the end of one response while staying alive for the next request.

List all daemons:

dmn --list
dmn mydaemon --list

Remove a daemon:

dmn --delete mydaemon
dmn mydaemon --delete

Send a signal (SIGUSR1 = 10) to a daemon:

dmn mydaemon -s 10

On POSIX, the signal is delivered to the backend process via kill(pid, signo). On Windows, dmn fires a named kernel event that the child process can wait on via WaitForSingleObject.


Parameters

Command/FlagDescription
<name> <cmd>Start or update a resident daemon command. Replaces any existing one.
<name> -d, <name> --deleteRemove a daemon if it exists.
<name> -l, <name> --listList one daemon if it exists.
-l, --listList all daemons as name<TAB>socket.
<name> -s <sig>, <name> --signal <sig>Send a signal to a daemon process.
<name>Relay standard input to a daemon.
-h, --helpShow help and usage.
-v, --versionShow version.

Public API

#include "dmn.h"

kc_dmn_t *ctx = kc_dmn_open();

kc_dmn_update(ctx, "app", "/bin/cat");
kc_dmn_list(ctx, "app");
kc_dmn_signal(ctx, "app", 10);  /* SIGUSR1 on POSIX */
kc_dmn_delete(ctx, "app");

kc_dmn_close(ctx);

Lifecycle

  • kc_dmn_open() - resolves runtime state and returns a context owned by the caller.
  • kc_dmn_update() - starts or replaces a named resident daemon command.
  • kc_dmn_relay() - relays stdin/stdout through a named daemon.
  • kc_dmn_signal() - sends a signal (POSIX) or fires a named event (Windows) to a daemon.
  • kc_dmn_list() - lists all daemon registrations or one named registration.
  • kc_dmn_delete() - removes a named daemon registration and terminates its process.
  • kc_dmn_path() - returns the resolved runtime directory for diagnostics.
  • kc_dmn_close() - releases the context.

Build

Compiled artifacts are generated under bin/{arch}/{platform}/ for the host architecture running the build.

make clean && make

Multiarch Builds

The project is prepared to build artifacts for multiple architectures under bin/{arch}/{platform}/. A plain make builds only the current host architecture, while the targets below build the full matrix or a specific target.

make all
make x86_64/linux
make x86_64/windows
make i686/linux
make i686/windows
make aarch64/linux
make aarch64/android
make armv7/linux
make armv7/android
make armv7hf/linux
make riscv64/linux
make powerpc64le/linux
make mips/linux
make mipsel/linux
make mips64el/linux
make s390x/linux
make loongarch64/linux

Beta Notice

This is a beta project tested only on Debian x86_64. It was created out of a personal need for these libraries, but no guarantees are provided regarding its stability or future support. You are free to test it, use it, and modify it as you please.

If you'd like to reach out, you can send an email to [email protected]. Please note that I do not accept pull requests; the goal is to avoid long-term dependency on platforms like GitHub, and I do not maintain fixed infrastructure to guarantee long-term stability for these projects.


Repo

You can download the repository and read the most up-to-date documentation directly from its official source.

GitHub: kaisarcode/dmn.c

License

GPLv3

This project is distributed under the GNU General Public License version 3 (GPLv3).