How to programmatically determine if the cron is running Is there any way programatically to determine when the cron is running (and if possible, what tasks are being run)? I've explored some options online that are bound to drupal_cron_run(), but no examples on how to listen for this method being used, as it is intended to start the cron.
In Drupal 7:

To determine if the current page request is a request for cron:
in other words, "is my code being called during cron"?

If you're running cron through cron.php, this is probably sufficient:

return strpos($_SERVER['REQUEST_URI'], 'cron.php') !== 0;


A more reliable way to determine a cron would be through introspection (e.g. debug_backtrace()), but that would entail a much greater degree of overhead.

To determine if any cron request is still running, across all Drupal threads and pageloads: in other words, "is any process running cron anywhere?" * Note that this method will fail if cron is stuck.

Drupal will programmatically set a variable called cron_semaphore while the cron is running. This variable is deleted once cron has completed. You can check for the presence of this variable to determine whether cron is currently active or not:

if (variable_get('cron_semaphore', FALSE)) {
  // cron is running
}


You can see the specific use of cron_semaphore in the documentation of drupal_cron_run().

The 'tasks being ran' will be implementations of hook_cron, which you can find using:

foreach (module_implements('cron') as $module) {
  $function = $module . '_cron';

  drupal_set_message($function . '() is being ran');
}