Terminate a process from linux terminal by name - ssh
Let’s say we want to end the process ssh
in another terminal because the connection is frozen due to network disconnect.
To do this, we need to identify the id
of the ssh
process, and end the process.
We will use:
- pipes (
|
) to redirect the output of one program to the next. ps ax
to list all processes in all terminalsgrep
to search for thessh
text in the output of theps
commandawk
to print the first word{print $1}
of the first lineNR==1
kill
command to end the process identified in theawk
line
To explain the concept of pipes (|
): we execute ps ax
to list all processes, and with the |
we pass the resulting output to the grep
command, which searched for the word ssh
: