linux: cannot use kill with verbose

60 views Asked by At

I try to find a list of processes and kill them using verbose option, but not successful.

$ kill --verbose -9 $(ps -eo pid,cmd | grep cmd_name | grep -v grep | awk '{ print $1 }')
bash: kill: -verbose: invalid signal specification

Then I try to put '-9' in front.

$ kill -9 --verbose $(ps -eo pid,cmd | grep cmd_name | grep -v grep | awk '{ print $1 }')
bash: kill: --verbose: arguments must be process or job IDs

If I don't use verbose, it seems working fine. But I like to use verbose here if possible.

BTW, I am using RHEL 8 and this is part of the man page.

       --verbose
              Print  PID(s)  that  will  be  signaled with kill
              along with the signal.
1

There are 1 answers

0
John Kugelman On

There's a pkill command that kills processes by name. Use that. All this ps | grep | grep -v grep stuff is so ancient.
(I'm not shaming you. I want to alert people who find this question on Google.)

pkill cmd_name

It doesn't have an option to both print and kill at the same time. If you want to also print the PIDs being killed you could leverage its companion command pgrep:

pgrep cmd_name | xargs --verbose kill