1

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?

3
  • 1
    If you are wondering why your question has bee closed, it's because CentOS 7 has been end of life for a long time now and should not be used in production anymore. Editing your question will not change that your environment is off topic here. Commented Dec 12 at 5:56
  • Then can you assist me for RHEL 9 , then will this question be opened ? Commented Dec 12 at 6:08
  • 1
    You don't tell us what your helper script looks like. What is in /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 :) Commented Dec 12 at 9:02

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.