Kill all currently running cron jobs

34,861

Solution 1

To kill all processes for the user, you have a few options. I like: su - username then kill -9 -1

To see which "cron" processes belong to user :

pgrep -u username cron

To kill those processes:

pkill -u username cron

Solution 2

Use:

kill -6 $(pgrep -U username cron) 

You can search with pgrep full string with -f arg if you need to kill specific cron jobs, while let others live.

kill signal is pretty dangerous really, so you should check what you are going to kill. If username is 'root' then you can kill important things, yes.

Share:
34,861

Related videos on Youtube

I wrestled a bear once.
Author by

I wrestled a bear once.

Yes I know the band sucks.

Updated on September 18, 2022

Comments

  • I wrestled a bear once.
    I wrestled a bear once. over 1 year

    For some reason my cron job scripts aren't exiting cleanly and they're backing up my server. There are currently a couple hundred processes running for one of my users. I can use the following command to kill all processes by that user, but how can I simplify this to kill only crons?

    pgrep -U username | while read id ; do kill -6 $id ; done
    

    It would be dangerous to run the above command as is, correct? Wouldn't that kill mysql and other important things?

  • I wrestled a bear once.
    I wrestled a bear once. over 9 years
    I think this might work if I add an -f
  • ewwhite
    ewwhite over 9 years
    Sure. Pointed in the right direction.