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 and kill
them.
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 and kill
them.
You might not need
pipe
for this, if you havepidof
command and know the image name, I did it like this:$()
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.You can also use killall:
Use
pgrep
with -f option.kill $(pgrep -f dmn)
In case there are multiple processes that you want to remove you can use this:
Note: You need to remove grep process itself from the output, that's why
grep -v grep
is used.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.