2

How to get pkill to output process information of killed process?

I don't see anything in man pkill that suggests this is possible. I know I can do a pgrep and process the list and then pipe that to kill but hoping this is in native pkill. I also don't see anything inside man kill that suggests this either.

Elijah Lynn
  • 965
  • 1
  • 11
  • 19
  • What process information do you want? `pgrep -a progname` will give you something in the style of `ps`. If you're using a specific system, there may be better than `pgrep` or `ps`. –  Mar 13 '20 at 16:06
  • I just want to output some user information in a script that kills an existing SOCKS tunnel that may have failed due to a re-connect. So, PID and command name I think. – Elijah Lynn Mar 13 '20 at 16:18
  • Looks like it does output in bash, but not fish shell. Maybe that is my issue. – Elijah Lynn Mar 13 '20 at 16:28
  • Use `/usr/bin/pgrep`. –  Mar 13 '20 at 16:30

1 Answers1

4

Use -e option: pkill -e program.

pkill --help:

-e, --echo                display what is killed

pkill -V:

pkill from procps-ng 3.3.15
GAD3R
  • 63,407
  • 31
  • 131
  • 192
  • `pkill: unknown option -- e` –  Mar 13 '20 at 19:17
  • @mosvy I have added my `pkill` version, please keep your comment, I hope we get an answer from `pkill` developer. – GAD3R Mar 13 '20 at 19:40
  • Notice that there's no linux tag ;-) –  Mar 13 '20 at 19:40
  • 1
    Looking at the GitLab repository, `-e` has been added to `pkill` in procps 3.3 (2012). It's probably safe to assume that it's available to most Linux users. OTOH non-Linux systems (I could test it on FreeBSD, "illegal option") most likely won't have it. – fra-san Mar 13 '20 at 21:39
  • 1
    Thanks for the version info! I just checked one system that is on `pkill (procps version 3.2.8)` which doesn't have it and then checked my local system (Arch) with `pkill from procps-ng 3.3.15` and there is no `-e` or `--echo` option in `man pkill` BUT ... IT WORKS!!! Yay! Marked as accepted answer, thanks! – Elijah Lynn Mar 16 '20 at 00:16
  • I added a screenshot, if it is confusing please edit and remove, if it helps please keep it. – Elijah Lynn Mar 16 '20 at 00:18
  • No one understands that it is not `-v` but `-e` and it is not mentioned on the `man` page. – Martin T. Jun 22 '22 at 07:48