Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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!

share|improve this question

2 Answers 2

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─┬─13*[cron───sh───longrunningscript_───php]
  │      └─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.

share|improve this answer
    
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
    
:) thanks a lot –  oBlank Aug 30 '10 at 16:12

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.

share|improve this answer
    
thanks a lot :) –  oBlank Aug 30 '10 at 16:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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