Cron Jobs Overflowing

Hi all, I have a question about cron jobs. When I execute certain scripts, I notice they begin to fill up in my running processes. For example, I see over 100 "cron: running job (cron)" when I do a ps ax.

My question is why does this happen? And is there a command or something that I can add in to my current scripts to stop it from repeating?

Thank you.
 
It happens because your scripts are running those other processes, all of which are being run by cron. I wouldn't worry about it.
 
Add something like this:

Code:
if [ -e /var/run/mysript ]
 echo 'Still running'
 exit
endif
touch /var/run/myscript
{do your stuff}
rm /var/run/myscript
 
I don't believe SirDice's script has any utility in your situation. It is designed to stop a single script from running again if it is already running.

Unless I misunderstood your first post, your situation is simply that your script is executing subshells (eg each individual command in a pipeline is run as a separate process in a subshell). Subshells show up as additional copies of your script in the process table because your script is their parent.
 
As I understood it the cronjob gets fired off even when there's still a previous one running.

To prevent this from happening you will need to add something to the script that indicates the script is running. The bit of code I posted does this. It exits if the 'marker' exists.
 
Back
Top