85

How can I stop a cron job which is currently running?

1
  • 3
    The three answers below interpret this question in three ways. @GURU, could you please clarify what you would like to do? Would you like to kill a process started by cron that is now running, or would you like to prevent the job running in the future? Commented Jul 29, 2011 at 3:51

11 Answers 11

46

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-name

or if you know the PID (you can determine it by running ps):

kill 1234

(substituting the actual PID)

7
  • 4
    how to list which currently running cron jobs ?
    – UWU_SANDUN
    Commented Sep 25, 2017 at 5:49
  • 11
    @UWU_SANDUN: You can use pgrep or grep the output of ps. There's nothing special about a process run from cron. You would just search for the process under its own name. You can also do ps fauxww | grep -A 1 '[C]RON' and lines below the line(s) will show jobs being run by cron. You can adjust the number 1 higher to see subprocesses if any. Commented Sep 25, 2017 at 13:26
  • Note you must be running cygwin as admin to kill processes. See here for more info on that.
    – takanuva15
    Commented Dec 22, 2017 at 16:56
  • Using Ubuntu I typed what @takanuva15 suggested, ps fauxww | grep -A 1 '[C]RON'. This lists the current cron jobs running, so thereafter you can note the PID down and execute # kill -9 PID. Thanks!
    – joninx
    Commented Nov 5, 2018 at 8:58
  • 1
    On mac I needed to do ps -A to show the cron job Commented Sep 5, 2019 at 3:36
28

Strange, no one has mentioned this method:

$ crontab -e

In 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_script2

after

* * * * * some_script1
#* * * * * some_script2

or

* * * * * some_script1

restart the service after making changes by

sudo service cron reload
1
  • 40
    This doesn't stop a currently running cron job, it stops future cron jobs that will be launch by cron.
    – Ivan
    Commented Nov 19, 2016 at 17:35
21

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

13

If you are using Redhat (RHEL)/Fedora Core/Cent OS Linux use the following command :

/etc/init.d/crond stop

If you are using Debian or Ubuntu Linux the following command :

/etc/init.d/cron stop

P.S : You should be root to do these things

4
  • 2
    i think it stops all crons .to stop particular cron may i know the command
    – GURU KUMAR
    Commented Jan 12, 2011 at 7:24
  • can u pls suggest any command sen
    – GURU KUMAR
    Commented Jan 12, 2011 at 7:27
  • I dont think it is possible in a straight way.. Maybe we should go for a hack. Commented Jan 12, 2011 at 7:29
  • 2
    This stops the crond daemon, does it also stop anything it spawned? You also generally always want crond running on a typical Linux system; there's a lot that usually depends on it running.
    – LawrenceC
    Commented Dec 30, 2020 at 16:31
12

First 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

ps-aux-output-meaning

0
3

You 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
  • 1
    That lists the crontab. Use crontab -e to edit it. For systems that have it, it's preferable to use sudo instead of su. Also, crontab -e would work for the user (or root) crontab, but not the system crontab (e.g. /etc/cron*). Commented Jan 12, 2011 at 11:40
2

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:

  1. Open crontab to edit:
 crontab -e
  1. Comment the commands in the crontab that needs to be stopped and save it. You can comment using '#'.
2

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.

1
  • Something like ps ax | grep $PID is far more functional than using top to check for processes, especially when there are more than a dozen. Commented Dec 30, 2020 at 19:53
1

Working for me for linux

pkill -9 crontab

Kills all process having process name crontab

0

First 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 \_ CRON

and now kill the process with this command

pkill -s 4288
0

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

You must log in to answer this question.