Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give arguments to kill via pipe [duplicate]

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.

like image 957
user567879 Avatar asked Dec 28 '11 09:12

user567879


People also ask

How do you kill multiple processes with one command?

killall Command – kill the processes by name. By default, it will send a TERM signal. The killall command can kill multiple processes with a single command. If more than one process runs with that name, all of them will be killed.

How do you kill with Sigkill?

The kill -9 command sends a SIGKILL signal indicating to a service to shut down immediately. An unresponsive program will ignore a kill command, but it will shut down whenever a kill -9 command is issued. Use this command with caution. It bypasses the standard shutdown routine so any unsaved data will be lost.

How do you pipe the output of a command to another command?

The | command is called a pipe. It is used to pipe, or transfer, the standard output from the command on its left into the standard input of the command on its right. # First, echo "Hello World" will send Hello World to the standard output.


2 Answers

kill $(ps -e | grep dmn | awk '{print $1}') 
like image 68
Daniel Persson Avatar answered Sep 22 '22 09:09

Daniel Persson


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.

like image 42
jcollado Avatar answered Sep 26 '22 09:09

jcollado