kill a waiting process using shellscript
Hai friends,
I would like to know to kill a process which is running infinitely using shell script in linux. Any help would be greatly appreciatable.. regards Ranmahs |
What you need to do it find the process ID (PID) of the process which is stuck in a loop, and then use the kill program to send it a signal which tells it to terminate.
Exactly how to identify it will depend on how the script is run. If the script is mad executable and called like a binary (i.e. the script is invoked directly by using the name of the script file), it will be in the process list under the name of the file. For example, say the script is called "my_script", you can find it like this: Code:
ps aux |grep my_script Code:
matthew 1080 0.2 0.2 4332 1508 pts/0 S 13:10 0:00 /bin/bash ./my_script To kill the script you use the kill program with the process ID you found, like this: Code:
kill 1080 Code:
kill -KILL 1080 |
Oh silly me, I omitted the much simpler thing... If the script is running in a terminal which you still have access to, you can just press control-C in that terminal.
|
Thanks for your replies...
But unfortunately that is not what i wanted.. i would like to identify whether the process is still running, my process named processname may take different time to complete which depends on the input.sometimes it may run infinitely.. so i would like to kill the process if it is running infinitely after 30seconds.. Right now i have a shell script with me as follows pl -s (path)../processname. &//running in background sleep 30 kill $(pidof processname) But this code will take 30 seconds eventhough my process complete before that particular time... now i want to kill the process either after 30 seconds or soonafter it completes...,which ever comes first. i found the following code from another thread,.. while ($!) // while the process is still running kill -SIGINFO $! // request info from the process sleep 1000 // wait a second wend But not workinng... regards Ranmahs |
Oh I see. Try something like this:
Code:
#!/bin/bash Related shell commands:
Another good term to search for the jobspec. Backgrounded (and stopped) tasks may be referred to by their PID, but from the shell which they are started from, also a jobspec. This is %1, %2 etc. You can also say %% for the last job you started (although this might change if the last job ends). You can also use name prefixes... Anyhow, I'll leave it to you to read up on the subject. |
That was awesome, great.....
I am running short of adjectives to praise your help... Thats xactly wht i wanted...! Thanx a lot... Regards Ranmahs:) |
All times are GMT -5. The time now is 03:34 PM. |