At times, different software solutions may need to incorporate cron like functionality. I ended up doing the same recently. As usual, I first tried to find out if there are any existing implementations of cron available so that I do not have to re-invent the wheel again. I was looking for a Python based implementation and found the following: http://sourceforge.net/projects/pycron/ (Python Cron, Great Cron for Windows).
Although the title mentions Windows but the implementation can work on any Python based environment. The software is GPL licensed. Its a small and simple implementation of Cron in Python. The solution is easy to read and understand. It helped me understand some of the intricacies of cron implementation (like matching the cron table information with current time, taking care of system clock issues, etc.).
The algorithm is based on the initial simple implementation of cron by Brian Kernighan.
- Read the cron file
- Determine if any commands are to be run at the current date and time and if so, run them.
- Sleep for one minute
- Repeat from step 1.