2

I'm looking for a software that can monitor a process (specified as a partial string/regexp match (e.g. grepping) in its full command-line) in terms of cpu and memory usage. If any of those processes exceed a certain cpu/memory limit for X cycles, the process in question should be killed.

Looking around a bit, I found monit, and ps-watcher.

  • Monit can monitor a process and its child processes by matching the process name, but it can't kill the particular process that exceeded the limit. It would rather take the pid of the first match.
  • Ps-watcher can match processes by their process-name and can kill the process that exceeded the limit. Bu it can't match processes via their full command-line. (not just the program name/path, but all potential arguments to it as well)

Any other alternatives? I had a simple shell script which did this before, but I didn't implement the cycles logic. There should be a tool which does this, I thought.

  • Not really a software, but you may find cgroups interesting. This kernel feature allows you to aggregate certain processes and control their use of system resources. – John WH Smith Oct 27 '14 at 14:42
  • Additional to Ps-watcher may be pgrep helps you? Like grep it can find out process by any kind of parameter and return pid (proces' id). – Costas Oct 27 '14 at 14:53
  • @Costas yeah, I think I used ps + grep actually in my script. But that wasn't what I was asking. Instead of going ahead and extending the script with the concept of cycles, I wanted to check if there is a tool that can already do this. – ParaDoX Oct 27 '14 at 14:57
  • @JohnWHSmith I know of cgroups, but haven't really used it much, will try it out to see if it can solve my problem. Also, rather than seeing all these processes aggregately, I actually want to see them separately and act on them with that information. What does cgroups do if e.g. the aggregate cpu load/memory usage exceeds the specified limit? Does it simply impose a limit so that they can't go higher, or actively prevent (e.g. by killing) processes from misbehaving? – ParaDoX Oct 27 '14 at 15:02
  • @ParaDoX This is a kernel feature, which means it works at the kernel level. In other words, it can work at the system calls level. Reaching a cgroups limit is one of the reasons why malloc can fail and return NULL, for instance. – John WH Smith Oct 27 '14 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.