# Cron Jobs Overflowing



## goosed (Jan 11, 2009)

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.


----------



## trev (Jan 11, 2009)

It happens because your scripts are running those other processes, all of which are being run by cron. I wouldn't worry about it.


----------



## SirDice (Jan 11, 2009)

Add something like this:


```
if [ -e /var/run/mysript ]
 echo 'Still running'
 exit
endif
touch /var/run/myscript
{do your stuff}
rm /var/run/myscript
```


----------



## goosed (Jan 11, 2009)

Thanks for the replies. SirDice, what exactly does that script do?


----------



## trev (Jan 12, 2009)

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.


----------



## SirDice (Jan 12, 2009)

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.


----------

