4

This question already has an answer here:

I read in an online flash card that the command is:

pkill -u bob $(pgrep -u bob)

However, I think this is wrong. I think it's saying:

Kill all the processed owned by bob, and 4572\n4600

Because:

[bob@localhost ~]$ pgrep -u bob
4572
4600

Also, it gives an error:

[bob@localhost ~]$ pkill -u bob $(pgrep -u bob)
pkill: only one pattern can be provided
Try `pkill --help' for more information.

Which makes sense because you can't have newlines in usernames, right?

I think the command should only be:

pkill -u bob

To "kill all processes owned by bob"

While the command:

pgreg -u bob 

Gives "all processes owned by bob"

I'm wondering:

  • Am I uses the right commands as intended?
  • Is my analysis of the incorrect way accurate?

marked as duplicate by imz -- Ivan Zakharyaschev, schily, roaima, sebasth, GAD3R Dec 12 '18 at 7:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

12

You Are Correct

Wrong: pkill -u bob $(pgrep -u bob)

Correct: pkill -u bob


The flash card probably meant to show:

kill $(pgrep -u bob)

which would kill all of the processes returned by pgrep -u bob.

  • 2
    alternatively, killall -u bob. – DopeGhoti May 19 '17 at 20:12
  • 1
    Not relevant on CentOS, but if you're ever on a Solaris machine, killall on there really just kills all processes, no patterns or anything. – Wieland May 21 '17 at 7:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.