Killing a stuck process in RHEL / CENTOS Linux
Performing a w (Who is logged in command) we see our currently process that we logged on, at 03:36. Above that is a process that has been idle for 20 hours.. Obviously this is a hung or “stuck” process. How do we find the process, and kill it?
Example 1-1
03:36:17 up 1 day, 9:49, 2 users, load average: 0.06, 0.10, 0.04
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
user1 pts/0 000.000.0.00 Mon06 20:38m 39:55 39:52 htop
user1 pts/1 000.000.0.00 03:36 0.00s 1.24s 0.12s w
[user1@blog ~]$
There are two ways we can find this process. If you look at the example above, you can see that the process that has been left running is ‘htop’
So if we perform a process list, and search for ‘htop’ using the grep command, we should be able to locate the process and get it’s process ID ‘PID’
HINT: I would always use SUDO here, to make sure you are able to see all processes.
Example 1 – 2 (ps output)
[user1@blog ~]$ sudo ps -ef | grep htop
[sudo] password for user1:
user1 4444 4308 3 Sep22 pts/0 00:40:04 htop
user1 7694 7648 1 03:42 pts/1 00:00:00 grep htop
You see that grep found two incidences of htop during the output of the ‘ps’ command, we can ignore the incidence on the bottom as that was the grep process we just spawned. The entry on the top is the one we are interested in.
Now that we know the PID ‘4444’ we can issue the kill command and terminate the process.
[user1@blog ~]$ sudo kill 4444
(There should be no output returned)
Now let’s issue the ps –ef | grep htop command again, to verify that it has been killed. You could also use the ‘w’ command instead.
Example 1 -3
User1 7968 7648 1 03:48 pts/1 00:00:00 grep htop
Remember, we can ignore this, as this is us using ‘grep’ to find htop. As you can see the process has been killed.
You can also find the PID by grepping for the terminal # or username of the user running the stuck processes.
Example 2-1 (ps –ef) – Searched by username $ sudo ps -ef | grep user01
root 4301 1625 0 Sep22 ? 00:00:02 sshd: user01 [priv]
user01 4307 4301 0 Sep22 ? 00:07:38 sshd: user01@pts/1
user01 4307 0 03:36 pts/1 00:00:06 -bash
user01 7984 7648 0 03:51 pts/1 00:00:00 ps -ef
user01 7985 7648 0 03:51 pts/1 00:00:00 grep user01
Example 3-1 (ps –ef) – Searched by terminal # ‘pts/1’ $ sudo ps -ef | grep user01
user01 4307 4301 0 Sep22 ? 00:07:38 sshd: user01@pts/1
user01 7648 4307 0 03:36 pts/1 00:00:07 -bash
user01 7648 0 03:52 pts/1 00:00:00 ps -ef
user01 7992 7648 0 03:52 pts/1 00:00:00 grep pts/1
HINT: You can use the kill command to terminate the session of a user. If you look at the examples above, notice the process sshd: ? If you terminate this process it will effectively terminate the session of the user. Observe.
[user01@blog ~]$ sudo kill 4307
[sudo] password for user01:
<Your ‘SECURE SHELL’ connection has terminated>
Comments
Killing a stuck process in RHEL / CENTOS Linux — No Comments
HTML tags allowed in your comment: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>