4

I have to develop an application in C++ to monitor the state of processes in my Linux system and also need to know if a new process is created or an existing process is terminated. Is there an API available for this? Also it will be helpful if someone could tell me how to start it with.

Jackzz
  • 1,417
  • 4
  • 24
  • 53
  • Are you talking about monitoring all Linux process in general, or some specific processes you create (and e.g. have control over)? There are many such programs out there that have this functionality (`procer` part of `mongrel2`, `systemd`. But you might be better off looking at something like `supervisord` or making a prototype using Python's [`psutil`](https://pypi.python.org/pypi/psutil) and when that works translate it into C++ (if you really have to). – Anthon Feb 16 '15 at 08:19
  • I need to monitor all processes.. – Jackzz Feb 16 '15 at 08:20
  • 1
    `ls /proc` should do the trick. there are probably other, older ways, but that's what I'd do. – strugee Feb 16 '15 at 19:54
  • With or without root access? – Gilles 'SO- stop being evil' Feb 16 '15 at 21:19
  • @Gilles: With root access.. – Jackzz Feb 17 '15 at 07:44
  • @strugee: You mean I have to look into proc filesystem at fixed intervals? – Jackzz Feb 17 '15 at 07:45
  • @Jackz yes. even better, use the inotify API. – strugee Feb 17 '15 at 20:10
  • @strugee: kk thankyou... will look into it.. – Jackzz Feb 18 '15 at 04:18
  • @Jackz disclaimer: I've never tried that before. good luck! – strugee Feb 18 '15 at 07:30
  • @strugee: inotify is really interesting.. But dont know why it has a problem with `/proc` filesystem. For all other directories I checked, it works absolutely fine. But not for `proc`. It doesnot notify when a new directory is created there.. – Jackzz Feb 18 '15 at 09:16
  • @Jackz really? I was afraid of that. too bad. – strugee Feb 18 '15 at 18:59

1 Answers1

1

inotify works well for all directories I tried, except the proc filesystem. So again I continued to search for a solution and where I reached was the proc connector and socket filters. Not much documented, but really worthy. Just have a look at:

http://netsplit.com/the-proc-connector-and-socket-filters

The way to reach this conclusion was through the answer provided by David Crookes to Detect launching of programs on Linux platform.

Hope it will help someone in future.

Community
  • 1
  • 1
Jackzz
  • 1,417
  • 4
  • 24
  • 53