Results 1 to 5 of 5
|
Enjoy an ad free experience by logging in. Not a member yet? Register.
|
|
-
02-28-2008 #1
- Join Date
- Jan 2008
- Posts
- 49
how to kill the process after specific time?
I need to define the specific duration to run a process. i mean after specific time the process should be killed autometically.
plese help me to do this.
Thanks.
-
02-28-2008 #2
- Join Date
- Feb 2008
- Posts
- 5
Run ur process
ps -e | grep "<process name>" | awk '{print $3}' ---This will give time
compare with ur required time and kill
-
02-28-2008 #3
- Join Date
- Jan 2008
- Posts
- 49
Thanks for your reply.
but again I will have to kill the process manually with this command if i am understanding this properly.
how will i run this command when i ll run the process? I mean if i run a process, at the same time can i define its duration? or after 5 hours this process automatically killed?
-
02-28-2008 #4
- Join Date
- Jan 2008
- Posts
- 49
Thanks ....
I have done this ....
see the example ... just wrote a small script
runtime=${1:-1m}
mypid=$$
cp /Database/Client_db_200802110231.BAK .&
cpid=$!
sleep $runtime
kill -s SIGTERM $cpid
echo "Both processes are terminated".
I mean now i can define the running time duration of all processes like cp with the time.
Cheers.
-
02-28-2008 #5
Originally Posted by samengr
I don't know of a clever way to kill a process after a certain amount of clock time passes. The best thing I can think of at the moment is a simple at job to run the kill command at the time you specify.
edit: Just noticed your kludge using sleep; glad you worked it out.