0

I had a cron script running on my Ubuntu PC ( 12.04.3 ) which periodically checks for disk space. There was a "sleep 5" also used in this script. This system was up for a month, but an issue is encountered. There were multiple instances of cron script running (around thousands) and multiple instances of "sleep".

When I killed one of the sleep process, cron script associated with it also completed.

Does sleep hangs often? Is it required to restart the machine to avoid this? Any other method to avoid this.

0

I think you have created a loop of things.

For example consider the following (bad) script, lets call it check.sh:

while :; du -sh /home/user >> /some/file 2>/dev/null; sleep 5; done

Now create a cron entry so that check.sh will run after every 30 minutes:

*\30 * * * * bash /path/to/check.sh

Lets consider the script first run at 10:00, the disk space will be checked and saved in a file. The tricky part is sleep 5, if you don't put a valid condition for closing it, it will pause the script for 5 secs and then will continue from the top meaning the same checking and writing operation. This loop will go on and on.

Again after 30 mins, cron starts a new process that will do the same thing over and over again. Remember the first process started by cron at 10:00 is still running.

This cycle will continue and in 6 hours you will have 13 of the same processes triggered by cron and most importantly every process is running in a indefinite loop.

In summary, while using cron you don't need things like sleep 5 unless your operation demands something like that, in the latter case put a valid condition so that the process does not run indefinitely.

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.