0

How can I make the result of one command to be an argument of another? I'm trying to kill child process by pid of parent process and use for it pgrep

Example: pgrep -P <PID>

But after I need to kill the PID which I get from pgrep

pgrep -P <PID> | kill - it doesn't work(

Thank you!

Avrel Dusop
  • 135
  • 3
  • 11

5 Answers5

1

With single pkill command:

pkill -P <PID> --signal SIGTERM

--signal signal
Defines the signal to send to each matched process. Either the numeric or the symbolic signal name can be used. (pkill only.)

RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105
0

Try this:

VALUE="$(pgrep -P <PID>)"
kill ${VALUE}
Bouramas
  • 1,077
  • 1
  • 17
  • 36
0

You use backticks for that. Like this:

kill `pgrep -P <PID>`
Kavli
  • 304
  • 1
  • 5
0

this should work for you

kill -9 `command`

and as far as getting the pid is concerned see examples below

kill -9 `pgrep executable`
kill -9 `pgrep ps`
kill -9 `pgrep bash`

or your command

kill -9 `pgrep -P <PID>`
asio_guy
  • 3,667
  • 2
  • 19
  • 35
  • You should **never start with `kill -9`**, since it won't allow the process to gracefully die (close file descriptors, free resources, etc). Instead, use `kill -INT`, or `kill -TERM` (the same as `kill`). Only as the last resort, use `kill -9`. – randomir Nov 02 '17 at 12:52
-1

You probably want "kill -9" as well:

pgrep -P <PID> | xargs -n1 kill -9

To test what it is going to do in advance try:

pgrep -P <PID> | xargs -n1 echo kill -9