Cron – How to stop long-running cron process from being killed

cronpython

I have a long-running cron process, running a Python script, that seems to get randomly killed. In dmesg I see:

[230568.077358] init: cron main process (890) killed by TERM signal
[237517.974422] init: cron main process (19598) killed by TERM signal

How do I stop this from happening? I tried running the process via a lower nice value, e.g.

* * * * * nice -n 10 bash -c "/usr/local/myproject/myscript.py"

but it still gets killed. How do I diagnose and fix this?

Best Answer

Your script is being killed as a secondary effect. The log message indicates that cron itself is being killed. When a process with child processes is killed, it sends a SIGHUP to its children, causing them to exit as well. That's what's killing your python script.

If the log line you list line is immediately followed by a line that says init: cron main process ended, respawning, then you know that something outside of init/upstart killed it and it was automatically respawned. If that message does not exist, then cron was killed by init/upstart, the same as if you ran "sudo restart cron" or "sudo stop cron".

So your new research project is figuring out what is either killing or shutting down cron.