Operating System - HP-UX
1753513 Members
5363 Online
108795 Solutions
New Discussion юеВ

Re: at command and finding sleeping process

 
SOLVED
Go to solution
Doug_3
Frequent Advisor

at command and finding sleeping process

Hi, I have issued at command with a script using a sleep 3600. I am trying to find the process id and kill it but do not understand how at is handling this. If I ps grep for the script, I see nothing. If I grep for the sleep command, I can see a process id. Is this the correct PID, if so do I kill the parent PID or is that a system process for cron/at? Thanks in advance,
Doug
8 REPLIES 8
Sundar_7
Honored Contributor
Solution

Re: at command and finding sleeping process

Doug,

Parent process of the at job will be cron. DO NOT kill cron.

UNIX95= ps -efH

Execute the above command. This will display the process tree.

Look at the time the sleep was started. If it matches with the time you scheduled the at job for, I would go ahead and kill the process

- Sundar
Learn What to do ,How to do and more importantly When to do ?
A. Clay Stephenson
Acclaimed Contributor

Re: at command and finding sleeping process

Sleep in this case is spawned as a child of the the script spawned by cron. If you kill the PID of sleep, you will kill the sleep command itself returning control to the parent script. It will probably then terminate normally. Kill sleep's PPID will kill your croned script not the cron daemon but simply killing sleep's PID should be sufficient unless your script loops and sleeps again.
If it ain't broke, I can fix that.
Mitra Rath
Occasional Advisor

Re: at command and finding sleeping process

Hi Douq,
A record of spooled at jobs is created in the /var/spool/cron/atjobs directory, where a separate file is
created for each job. This file contains commands to be executed and the values of environment variables.Or u can use "at -l" to list the current jobs...

Mitra
Doug_3
Frequent Advisor

Re: at command and finding sleeping process

Thanks Clay, the script does loop with a while true;
sleep;
test and execute cmd;
exit;
Is there anyway to kill the "script" or do I just have to let it run it's course?
Sundar_7
Honored Contributor

Re: at command and finding sleeping process

# echo "sleep 3600" >> somescript
# chmod +x somescript
# at now
/home/root/somescript
warning: commands will be executed using /usr/bin/sh
job 1110924606.a at Tue Mar 15 17:10:06 2005
#
# UNIX95= ps -efH | more
...............
root 2252 1 0 Jan 23 ? 00:15 /usr/sbin/cron
root 10295 2252 0 17:10:13 ? 00:00 sh
root 10296 10295 0 17:10:13 ? 00:00 sh
root 10297 10296 0 17:10:13 ? 00:00 sleep 3600
...............
#

Just kill the sleep - you should be fine.
Learn What to do ,How to do and more importantly When to do ?
Bill Hassell
Honored Contributor

Re: at command and finding sleeping process

The shell which is the parent of sleep is running the script. It this is an infinite loop script, then killing the sleep process will return to the shell and start another sleep. In that case, you kill the parent of sleep which should be sh. You'll see two sh's typically, one that is running the script (parent of sleep) and one that is run by cron which the starts the subshell to run the script. Just kill the lowest sh process and the job should terminate cleanly. Always use kill -15 (never kill -9) so processes can clean themselves up correctly.


Bill Hassell, sysadmin
Gerhard Roets
Esteemed Contributor

Re: at command and finding sleeping process

Hi Doug

Do a ps -ef and find your process. Look for the PPID colom. DO a ps -ef and pipe the grep for the PPID. If it is the correct one ... kill the parent and then the child.

HTH
Gerhard
Doug_3
Frequent Advisor

Re: at command and finding sleeping process

Close thread, thanks for the generous replies.