I am trying to figure out a way to get a notification when one of my processes starts to run once again (i have tried monitoring the proc file but didn't succeed, monit doesn't handle getting the same pid and runs periodically). any ideas?
4 Answers
In my opinion, your first idea about using Monit was the best approach and is the more robust.
i have tried monitoring the proc file but didn't succeed
Tell us where you are stuck, we could help. Monit is fully able to do that. Maybe you have a misconfiguration of Monit somewhere.
monit doesn't handle getting the same pid
Right, but you should not be worried about that. The way Linux systems manage processes, you will never get the same PID as the previous one.
- https://stackoverflow.com/questions/11323410/linux-pid-recycling
- https://unix.stackexchange.com/questions/26677/will-process-ids-be-recycled-what-if-you-reach-the-maximal-id
- http://en.wikipedia.org/wiki/Process_identifier
and (Monit) runs periodically
Right. Monit has a default polling interval of 120 seconds. If this lantency is not suitable for you, you can reduce the polling interval by changing the value of set daemon n (where n is a number in seconds - default 120)
parameter in config file.
-
i have tried monitoring the proc with "inotify" and didn't succeed. (didn't try this with monit because didn't know how) – vivi Jan 13 '14 at 04:57
maybe something completely different. A simple wrapper.
write a bash script put in on place of original binary
#!/bin/bash
# put here commands to notify You
# optional commands to redirect fd to original processs if needed
exec /path/to/original/binary
Your questions has not much details about what exactly You expect but this would do the job.
![](../../users/profiles/204310.webp)
- 1,726
- 1
- 13
- 17
-
just to be clear- each time a program restarts i want to start running a simple program that prints that one of the programs restarted. – vivi Jan 13 '14 at 04:59
You can be notified of process-related kernel events via Netlink. See here for example code.
![](../../users/profiles/175822.webp)
- 115
- 6
you can write a program that get the processes list and parse this list and detect new processes. then add a "http xml value sensor" to your monitoring software(cacti, ...) and check your program results.
http://www.cyberciti.biz/faq/show-all-running-processes-in-linux/
![](../../users/profiles/188992.webp)
- 86
- 1
- 9