sometimes, we found our server's cron process auto repeated, repeated 2 or 3 times

when use ps command, I get this:

server_xx14:~ # ps aux | grep cron

root      2596  0.0  0.0  11188   392 ?        Ss    2009   0:25 /usr/sbin/cron
root     21706  0.0  0.0  20812   944 ?        S    09:30   0:00 /usr/sbin/cron
root     23437  0.0  0.0  20812   944 ?        S    09:40   0:00 /usr/sbin/cron

I only want just one cron to running, how can i fix this problem? thx!


If you have some long-running and/or failing (never finishing) scripts in cron, they will cause multiple cron processes appearing in the process list.

To see what's going on, try pstree -ap and see the cron stuff in a nicely formatted manner, like the one below:

  │      └─cron───sh───longrunningscript_───php

That would mean cron had started a new shell script, which starts PHP, which takes a long time to run. If pstree is not installed in your system, ps -auxwwwf creates a similar view.

If cron behaved any differently, a single long-running cron job might stall all the other scripts meant to run in cron indefinitely. And THAT'S something you don't want.

  • what I should do when there is some long-running and/or failing (never finishing) scripts in cron,is there any suggestion? – oBlank Aug 30 '10 at 9:47
  • Run them by hand and see why they are taking so long. – Janne Pikkarainen Aug 30 '10 at 9:48
  • some crons need to read and calculate a lot of datas from database. is there possible to enforce only one cron to run, no matter how long the scripts will running? – oBlank Aug 30 '10 at 11:40
  • Enforcing has to be done on per-script basis. One popular way is to modify the script to use a lockfile in the beginning of the script and get it deleted at the end of the script. If another cron tries to start the same script, it won't because of the lockfile. There are many ways to do that, dotlockfile utility bundled at least with Ubuntu 10.04 is a very nice one :) – Janne Pikkarainen Aug 30 '10 at 11:45

What OS are you running? You should definitely only have 1 instance of cron running. Try running:

# /etc/init.d/crond stop
# /etc/init.d/crond start

Or which ever init.d script your OS uses to kick off cron. If that doesn't work, you can probably run the stop command, then kill the remaining cron processes, then running the start.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.