title: How exactly cron works?
body: <p>I want to implement a simple C++ class that parses a cron entry and executes a task on specified schedule. Wiki says cron have implemented following algorithm:</p>
  
  <ol>
  <li>On start-up, look for a file named .crontab in the home directories of all account holders.</li>
  <li>For each crontab file found, determine the next time in the future that each command must run.</li>
  <li>Place those commands on the Franta–Maly event list with their corresponding time and their "five field" time specifier.</li>
  <li><p>Enter main loop:</p>
  
  <ul>
  <li><p><strong>Examine the task entry at the head of the queue, compute how far in the future it must run.</strong></p></li>
  <li><p>Sleep for that period of time.
  On awakening and after verifying the correct time, execute the task at the head of the queue (in background) with the privileges of the user who created it.</p></li>
  <li>Determine the next time in the future to run this command and place it back on the event list at that time value.</li>
  </ul></li>
  </ol>
  
  <p>I'm only interested in the bold part. Given current time (<code>2015-11-07 14:48:03</code>) and a cron entry (<code>0 0 * * 1 *</code>) how can I determine the time distance (seconds) to the upcoming execution point?</p>