user1876712
user1876712

Reputation: 113

Linux kill - Do not exit program

I am killing a process inside a script using kill -9 command. The process gets killed but control is exiting from the script. How do i make the following statements work after the kill command?.

kill -9 `ps -ef | grep /home/myFile | grep -v grep | awk {'print $2'}`

sleep 5

echo Process Stopped

Here both sleep and echo are not working. Can some one help?

Upvotes: 0

Views: 572

Answers (1)

ymonad
ymonad

Reputation: 12090

if you have pkill installed in your machine, you should use it

$ pkill -9 -f /home/myFile

if not, may be you can use the ancient trick instead of grep -v grep

$ kill -9 $(ps -ef | grep '[/]home/myFile' | awk {'print $2'})

The trick is [/]home/myFile. grep'ing [/]home/myFile matches to /home/myFile, but argument shown in ps does not contain grep /home/myFile.

Upvotes: 1

Related Questions