krishna
1
Hi all,
I have given a command in the unix machine :
$kk.sh &
kk.sh is running in background process, I want to kill the that
job after 1 minute, I tried to find out the process id, by giving
this command
$ps -eaf |grep kk.sh
nothing I found, so, how can I kill that process ?
please reply to ::email removed::
Thanks
krishna
PxT
2
If the script does not show up in the 'ps' listing, then it must already have completed.
For jobs running in background (invoked with &) -
type jobs at prompt to see all jobs.
You can kill these jobs with "kill -9 %#" where %# is %1 or %2 or whatever the number of the job. (note: % is the percent sign)
When a background job finishes, you should be notified with a "Done" response.
The variable $! will also contain the PID of the last job you invoked in background.
If you invoke kk.sh from within another script:
#!/usr/bin/ksh
kk.sh &
BG_PID=$!
sleep 60
kill -9 $BG_PID
To kill the job after 1 minute.
Also the wait command will return the return code ($?) of the background job as well...
kk.sh &
wait
echo $?