How to give arguments to kill via pipe
Solution 1
kill $(ps -e | grep dmn | awk '{print $1}')
Solution 2
In case there are multiple processes that you want to remove you can use this:
ps -efw | grep dmn | grep -v grep | awk '{print $2}' | xargs kill
Note: You need to remove grep process itself from the output, that's why grep -v grep
is used.
Solution 3
You could use
pkill dmn
if your system has the pkill command.
Solution 4
You might not need pipe
for this, if you have pidof
command and know the image name, I did it like this:
kill $(pidof synergyc)
$()
I understand this as it converts that output to a variable that kill can use, essentially like pipe would do. Shorter and easier to understand than some other options but also maybe less flexible and more direct.
Solution 5
If you have the pidof
command on your system ( I know shells such as ZSH come with this by default, unless I'm mistaken), you could do something like.
kill -9 $(pidof dmn)
user567879
Updated on November 09, 2020Comments
-
user567879 over 3 years
I need to search for a certain process and kill that process. I wrote a command like this:
ps -e | grep dmn | awk '{print $1}' | kill
Where the process name is
dmn
. But it is not working. How can I find processes by name andkill
them.