Score:0

Killing multiple processes by name

cn flag

I have a question regarding killing processes that are running (and that I have started)

I have started many procesess and now I want to terminate them

doing

ps aux | grep aword

gives me the processes I want to kill. (aword being a word related to the processes) There are a lot so it takes me a while to kill them all

I would like to do it faster. Now a peculiarity of these processes is that some have as USER "theuser" and some have "root" I tried and it seems I have to kill first the ones with "theuser" because if I try the roots first , the process comes back to life.

So my question is how can I kill all the processes that come out of the grep command above but in the order that first the ones by "theuser" and then the ones with root (which require sudo of course)

waltinator avatar
it flag
`pgrep` and `pkill` are the tools for this. Read `man pgrep`. Consider doing this in 2 steps - kill the `$USER` processes first, then kill the `root` processes.
Score:3
jp flag

You better use pkill(alone) for that task:

  • Kill processes by name(partial/full match):

    pkill 'name'
    
  • Kill processes by name(exact match):

    pkill -x 'name'
    
  • Kill processes by full command line(partial/full match):

    pkill -f 'command'
    
  • Kill processes by full command line(exact match):

    pkill -xf 'command'
    

Run it without sudo to attempt to only kill matched processes "kill-able" by the invoking user or with sudo to attempt to kill all matched processes.


Notice: A dry-run(i.e. only print matched process IDs without killing them) can be done with changing pkill to pgrep or pgrep -l and pgrep -a(respectively, to also print process names and full command lines) ... For example:

pgrep 'name'

or:

pgrep -l 'name'

or:

pgrep -lx 'name'

or:

pgrep -lf 'command`

or:

pgrep -lxf 'command'

The same goes for pgrep -a as well.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.