tj/mon
Freemon(1) - Simple single-process process monitoring program written in C
FreeFree tier
About tj/mon
mon(1) is a super-simple, single-process monitoring program written in C. It is designed as a lightweight alternative to complex tools like monit, using less than 400KB of memory and offering a straightforward setup. mon automatically restarts a specified command if it exits, with configurable retry attempts, logging, and hooks for restart and error events. It can be daemonized and managed via shell scripts, avoiding awkward DSLs.
Key Features
Written in C with less than 400KB memory footprint
Monitors a single command and automatically restarts it on failure
Configurable retry attempts within a 60-second window (--attempts)
Custom commands on restart (--on-restart) and on final error (--on-error)
Daemonize mode (--d) to run in the background
Logging with optional prefix (--log, --prefix)
Pidfile support for managing multiple mon processes (--pidfile, --mon-pidfile)
Simple installation via make or curl extraction
Pros & Cons
Pros
- Extremely lightweight (<400KB memory usage)
- Simple to set up and configure using shell scripts
- No complex DSL or configuration file required
- Open source and free to use
Cons
- Monitors only a single process per instance
- No built-in alerting mechanisms beyond custom scripts
- Limited to restart logic and basic logging; no advanced monitoring (e.g., CPU, memory usage)
Best For
Keeping a critical server process running continuouslyDaemonizing and managing background services via shell scriptsAutomated restart and alerting for unstable programsLightweight process supervision without heavy configuration
FAQ
How do I install mon?
Run 'make install' from the cloned repository, or use the one-liner: 'mkdir /tmp/mon && cd /tmp/mon && curl -L# https://github.com/tj/mon/archive/master.tar.gz | tar zx --strip 1 && make install && rm -rf /tmp/mon'.
How do I manage multiple processes with mon?
mon is designed to monitor a single program per instance. To manage multiple processes, run multiple mon instances in a shell script, each with its own pidfile and daemonize flag.
What happens when mon runs out of attempts?
After exceeding the maximum number of retries (default 10 within 60 seconds), mon executes the --on-error command (if provided) and then exits with a failure message.