dtazv
July 22, 2005, 5:54am
1
Hi,
Thanks in advance.
i need to kill a unix background running job after that job process completes.
i can kill a job by giving the following unix command
kill -9 processid
how to kill the job after the current process run gets completed ?
Appreciate your valuable help.
Thanks - Alo
vino
July 22, 2005, 6:43am
2
Wouldnt the background process get killed after its run ?
Look at this.
sh-2.05b$ cat sleep.sh
#! /bin/sh
echo "Going to sleep"
sleep 30
echo "Back from sleep"
sh-2.05b$ ./sleep.sh &
[1] 24400
sh-2.05b$ Going to sleep
sh-2.05b$ ps x | grep sleep | grep -v grep
24400 pts/11 S 0:00 /bin/sh ./sleep.sh
24401 pts/11 S 0:00 sleep 30
sh-2.05b$ Back from sleep
sh-2.05b$ ps x | grep sleep | grep -v grep
sh-2.05b$
And there is no trace of sleep.sh
What is happening in your case ?
Vino
please check the sleep.sh, i ll come dear
guhas
September 10, 2005, 12:54pm
4
check fr the status the status of the process fr which ur job is going to wait ... once it is done take the wait status and end the job
98_1LE
September 10, 2005, 1:50pm
5
This will fork off a background process to kill the script after DELAY
#!/bin/bash
DELAY=600 # seconds
kill (){
sleep $DELAY
kill $0
sleep 1
kill -9 $0
}
kill &
# Do other stuff for $DELAY seconds
Assuming you have :
Have'nt tested it!
#!/bin/bash
my_function()
{
echo "This is my function"
}
my_function &
echo "Some Statement"
MY_PID=$!
kill $MY_PID
check the last line on your process --- does it end with "exit 0" or does it end with the last process command? i tend to make sure my scripts' last line is "exit 0" just to make sure i don't have any process that's hanging on too long past it's shelf life ...
#! /bin/ksh
echo "My name is Johnny."
echo "The date stamp right now is $(date)."
exit 0 ## last line
guhas
September 28, 2005, 7:18am
8
can we handle the killing of a different script from another script.
i mean can u kill the script 'myscript' from another script wen my script is running