Multiple PID for the same script

Hi All,

I have scheduled one script using cron but it's not running. On investigation i have found there are 4 PIDs for the same script.

Please suggest on the following:

  1. Is it normal to have more than 1 PID for the script which is being run using cron command?

  2. How can avoid the problem and start the script to behave normally?

  3. Can i kill all the pid's related to the script and then will cron automatically start(new PID) the script?

Thanks in advance

This all depends on how the script is coded. With no information, I am guessing the script is hanging for some reason.

  1. kill off the all of the processes running the script
  2. Edit your script: either use some kind of lockfile or search ps output for more than 1 occurrence of your script
  3. Make sure the cron envrionment - especially the PATH - is exactly the same as yours is when you test the script and it works. This includes the current working directory.
  4. Don't use relative paths to files.
  5. Change the cron entry to have the script create a log file .. myscript > /path/to/logfile

Other than that I cannot help you...

What is that script trying to do..? Are you calling any other scripts/applications inside your script? If that is the case, what you are referrung may be the child processes.

Make entries in the script before the startup to see any existing processes and kill it(its not a fair idea to kill the process if you have a neat option to stop the application process/script)..

Something like below can be used to kill the process.

ps -ef| grep "application" | grep " 1 " | xargs kill -9

Hi All,

The script which is in question is used for deleting the files based on the timestamp which have been calculated using some logic.

The script is not calling any other script.

Now, please suggest:

  1. Can I kill all the PIDs related to the script so that it can be started again succesfully. The script is already in the production environment, therefore can't make any other changes. Before moving it to the production, it has been tested successfully and worked in the production environment as well.

  2. I see 4 PIDs in total for one scrip of which 2 shows running state and other 2 sleep state.

I need your inputs before Killing the PIDS.