29 December 2017

Simple ProcMon - Putting all things together

I have written few posts on process management in Python - fork, exec, wait, and exit. These are exactly same Python APIs around system APIs provided by Linux/Unix/POSIX. In this post, I am going to talk about putting things together and create a simple process monitor.

Read how to fork, exec, wait and exit before proceeding with this post.

Functionality of Simple Process Monitor
  1. Have the list of processes that need to be monitored in the INI file. Let us call this configuration
  2. Load the configuration file
  3. Start the process
  4. Exec the new program
  5. Loop #3 and #4 until all the processes are loaded
  6. Monitor the process (wait). A simple call to "wait" would listen for a child to exit.
  7. When a child dies, handle it either by restarting the process again or do nothing (depending on how it is configured).
  8. Go back to #6 and continue the monitoring
It is going to tough to post all the code here. Refer my GITHub for the code. Feel free to extend or write tests

Experience: It is another personal experience on higher productivity claim of Python. I wrote the code in a couple of hours and spent around 2 hours on refactoring. Given my (lack of) experience in Python, Python seems to fulfill its promise.