How can I stop a cron job which is currently running?
111 Answers
You can do this the same way you'd stop any process.
To stop a currently running cron job, you can do one of the following:
pkill process-nameor if you know the PID (you can determine it by running ps):
kill 1234(substituting the actual PID)
6Strange, no one has mentioned this method:
$ crontab -eIn the opened editor, delete line of the task you want to stop or insert a # sign, save and exit
e.g.
before
* * * * * some_script1
* * * * * some_script2after
* * * * * some_script1
#* * * * * some_script2or
* * * * * some_script1restart the service after making changes by
sudo service cron reload 1 To stop running cron job .First get the process id of your command with
top -p $(pgrep -d',' your_command)
eg:-
top -p $(pgrep -d',' httpd)
and run
kill PID replace PID with process id
If you are using Redhat (RHEL)/Fedora Core/Cent OS Linux use the following command :
/etc/init.d/crond stopIf you are using Debian or Ubuntu Linux the following command :
/etc/init.d/cron stopP.S : You should be root to do these things
4First type ps aux to see what all processes are running.
Then note down the PID of each process you want to stop
Then type
kill {PID} for each process.
Also do have a look at these links (superuser links) :
Verify-that-a-cron-job-has-completed
0You can edit the cron table and comment out the task in question. Switch to the user that controls the task, export your editor of choice into the environment, then use crontab -l:
$ su - root
...
# EDITOR=vi; export EDITOR
# crontab -l 1 If you want to remove all the crontabs that are running (the commands will be lost):
crontab -r ... or If you want to stop some commands on crontab:
- Open crontab to edit:
crontab -e- Comment the commands in the crontab that needs to be stopped and save it. You can comment using '#'.
This is my take on this, which I use from time to time.
First, let's find the process IDs of the processes cron has started by using:
systemctl status cron This will give you a nice little process tree.
Each process' ID are the numbers displayed to the left of the process' name.
So, if my process ID for a process started by cron is 2234225, then I'll simply go:
kill 2234225 I can check either with:
systemctl status cron or
top that the process has been terminated.
Just remember, if the process in question is set to be started as defined by the crontab
crontab -e then, the process in question will become activated again, just with a different process ID.
1First of all check the working process with this command.
ps -o pid,sess,cmd afx | egrep "( |/)cron( -f)?$"This command's output is
599 599 cron
4288 599 \_ CRONand now kill the process with this command
pkill -s 4288 Working for me for linux
pkill -9 crontabKills all process having process name crontab
If you are using Redhat (RHEL)/Fedora Core/Cent OS Linux use the following command :
$ sudo systemctl status crond
If you are using Debian or Ubuntu Linux the following command :
$ sudo systemctl status cron