Operating System - HP-UX
1822439 Members
2712 Online
109642 Solutions
New Discussion юеВ

how to kill specific cron job

 

how to kill specific cron job

I have a job running under cron which I want to kill. Thing is I'm not sure what exactly I should be killing! Beneath what appears to be the main cron daemon (/usr/sbin/cron owned by root) there are 2 child processes (one the parent of the other) running from what I think is the correct directory (ps -ef is being cut off) and under the correct user. Then the lowest child process branches giving a total of 4 more child processes! I'm scared of killing the wrong thing.

Is it easiest just to kill the main cron daemon then restart using:

# /sbin/init.d/cron stop
# /sbin/init.d/cron start

or are there implications to doing this on a 24/7 prod system.

All input very gratefully received.

James.
6 REPLIES 6
Jose Mosquera
Honored Contributor

Re: how to kill specific cron job

Hi,

A little example about:

#ps -ef|grep
root 3930 3929 0 Jan 25 ? 93:40
#kill -9 3990

-9 is the signal number, the following table describes a few of the more common signals that can be useful.

signum signame Name Description
___________________________________________________________________________
0 SIGNULL Null Check access to pid
1 SIGHUP Hangup Terminate; can be trapped
2 SIGINT Interrupt Terminate; can be trapped
3 SIGQUIT Quit Terminate with core dump; can be trapped
9 SIGKILL Kill Forced termination; cannot be trapped
15 SIGTERM Terminate Terminate; can be trapped
24 SIGSTOP Stop Pause the process; cannot be trapped
25 SIGTSTP Terminal stop Pause the process; can be trapped
26 SIGCONT Continue Run a stopped process

Rgds.
John Poff
Honored Contributor

Re: how to kill specific cron job

Hi,

I would try killing the two child processes. If the other processes are well behaved they should die also.

I would NOT do a 'kill -9' until you have exhausted all the other, safer signals first. Try 'kill -15', 'kill -2' first. The 'kill -9' will nail the processes and they will leave open any files, shared memory segments, etc. that they had open.

JP
Ricardo Bassoi
Regular Advisor

Re: how to kill specific cron job

Hi James,

Like you run the program using the cron utility, maybe its a good idea to create a script that check the child process and kill them !
You can put the lines :

ps -ef | grep

take the pid from the process and so kill it:

kill or
kill -9

Regards,

Ricardo Bassoi
If you never try, never will work
Chris Vail
Honored Contributor

Re: how to kill specific cron job

Starting and stopping cron will not stop the jobs spawned by cron. Others have posted the signals to use with the kill command, but don't be afraid to use them IF you are familiar with the application being run. Start by killing the child processes, then the parent, but don't kill cron itself. If you use kill -9, any files will remain open, and there might be other problems.
Sometimes, hitting them with a kill -9 won't kill them, but cause them to become zombies. These can only be killed by a system reboot.
Basically, if you use kill -9 a process, check again the process ID with ps -ef|grep PID. If the process ID remains, and its parent is 1 or 0, you've probably created a zombie. You can try kill -9 on that process as many times as you'd like, but if it doesn't go away, you'll have to schedule a reboot to clean up the process table. Usually, zombies are more of an annoyance than an actual problem. However, there are situation where they hold a file descriptor open, or otherwise get in the way of another process. If the application is properly written, a kill -15 terminates it properly, and you won't have to go to the extreme measure of using the kill -9.

Good Luck
Chris
Jeff Schussele
Honored Contributor

Re: how to kill specific cron job

Hi James,

Just a tip on using ps. If you want to see more of the actual command line use:

ps -efx

and you'll get extended output.

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Paul Sperry
Honored Contributor

Re: how to kill specific cron job

Before you resort to -9 try using kill -11; it's almost as sure a kill and it does clean up so that file descriptors are closed and shared memory is detached.