How to kill all processes with the same name?

2

I want to kill all processes with the same name that belong to a user, for example:

$ps -u user_1
2345 myapp
2346 myapp
2347 myapp
2348 myapp2
2349 myapp

I want to kill all "myapp" processes that belong to "user_1", how can I do this?

alwbtc

Posted 2013-01-02T07:13:19.290

Reputation: 2 367

2To kill all processes, use killall. I'm not kidding: man killall. – cpast – 2013-01-02T07:14:56.953

Here's a link to a discussion on askubuntu that might answer your question.

– dinesh – 2013-01-02T07:45:50.717

Answers

1

You can use the pkill command.

pkill -u user_1 myapp

Note that myapp2 won't be killed as it has a different name.

jlliagre

Posted 2013-01-02T07:13:19.290

Reputation: 12 469

0

use pkill command and wild cards

pkill -u user_name 'myap*'

it will kill all processes starting with myap.

"?" - matches 0 or 1 character

"*" - matches 0 or more character

Arpit

Posted 2013-01-02T07:13:19.290

Reputation: 167

@Aprit I don'T believe that killall supports wildcards, which forces you to be very precise when passing the name of the process you would like to terminate. – rbaleksandar – 2018-04-19T12:57:50.613

1and @cpast is right. killall will do the same. – Arpit – 2013-01-02T07:42:37.837