XgigPro
XgigPro

Reputation: 134

How to kill a process except one?

I have few processes starting with string apple. So my processes names are apple1, apple2, apple3 till apple10. Now I use command "pkill -f apple". But it kills all processes starting with apple. I want apple2 not to get killed with the above command. So can someone tell me how the above command can be modified?

Upvotes: 1

Views: 1966

Answers (1)

Saranya Sridharan
Saranya Sridharan

Reputation: 226

This works for excluding the apple2 pid from the list and kill others , Not sure if your problem will be solved with this.

ps -aef | grep apple | grep -v apple2 | awk '{print $2}'|while read pid
do
kill -9 $pid
done

Upvotes: 2

Related Questions