killing a unix job after the job process gets completed

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

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

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

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

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