I need to automatically end processes running for more than 24 hours on a CentOS 7 server. I’m using Monit to detect long-running processes and execute a custom script.
To test it, I reduced the threshold to 30 seconds and used a dummy process:
sleep 5000 & echo $! Monit configuration:
# /etc/monit.d/test_uptime.monitrc check process test_sleep matching "sleep" if uptime > 30 seconds then exec "/usr/local/bin/monit_kill_sleep.sh" if does not exist then alert Monit validates correctly:
sudo monit -t Control file syntax OK Monit also logs that the uptime rule is being triggered:
'test_sleep' uptime test failed for sleep -- current uptime is X seconds 'test_sleep' exec: '/usr/local/bin/monit_kill_sleep.sh' My helper script logs when it runs:
=== 2025-12-11T16:50:57 monit_kill invoked === no sleep processes found But the sleep process is definitely running:
pgrep -a sleep 235589 sleep 5000 Monit calls the script, but inside the exec environment it is unable to see or kill the process. Even using a robust helper script with full paths (/usr/bin/pgrep, /bin/ps, /bin/kill) results in "no sleep processes found" when invoked by Monit. The script works when run manually.
Monit runs as root and has access to /proc. PATH is set inside the script and full paths are used, but Monit’s exec environment cannot see the process.
My question: Why does Monit’s exec environment fail to see or kill a simple sleep process, even though it is running and visible from the shell, and the uptime rule triggers?
What am I missing in Monit’s execution environment or process matching?
/usr/local/bin/monit_kill_sleep.sh. And yes, if you reproduce the problem on RHEL9 it's on-topic. Note that we expect you to reproduce the problem on RHEL9, not just edit the question :)