DEV Community

Cover image for Killing a defunct process
Eden Jose
Eden Jose

Posted on • Updated on

Killing a defunct process


Encountered this when I was trying to install htop on one of my test-RHEL EC2 instances. I was following the steps in this link.

I've also learned that defunct processes are almost similar with zombie processes, but there's also some differences which you can read here.


What happened:

  • Two terminals opened, both connected to same instance
  • installed the package on second terminal while update was running on first

Got this message on second terminal when trying to install package and update simultaneously:

Running transaction check
Waiting for process with pid 5941 to finish.
Enter fullscreen mode Exit fullscreen mode

Checking which process is that

$ ps -ef |grep 5941
root        5941    5939 18 06:00 pts/0    00:01:42 yum update -y
root       36173   36153  0 06:09 pts/2    00:00:00 grep --color=auto 5941

Enter fullscreen mode Exit fullscreen mode

Since it was taking some time, I had to cancel the update running on the first terminal so I can install some packages first and then run the update again.

When I try install the packages again, it still returned same messaged about the same pid. Checking the processes again, it now showed "defunct"

$ ps -ef |grep 5941
root        5941    5939 18 06:00 pts/0    00:01:42 [yum] <defunct>
Enter fullscreen mode Exit fullscreen mode

I tried killing by running kill -9 5941 but it still appear as a "defunct" process.

What this means

Based on one of the link I found online:

From your output we see a "defunct", which means the process has either completed its task or has been corrupted or killed, but its child processes are still running or these parent process is monitoring its child process. To kill this kind of process, kill -9 PID doesn't work. You can try to kill them with this command but it will show this again and again.

What to do

Determine which is the parent process of this defunct process and kill it. To know this run the command:

$ sudo ps -ef|grep defunct
UID          PID    PPID  C    
root        5941    5939  6 06:00 pts/0    00:01:42 [yum] <defunct>
eden       36210    6097  0 06:24 pts/2    00:00:00 grep --color=auto defunct

Enter fullscreen mode Exit fullscreen mode

Then run the sigkill cmmand again but this time include both the PID and PPID.

$ sudo kill -9 5941 5939
$ sudo kill -9 36210 6097
Enter fullscreen mode Exit fullscreen mode

Verify the defunct process is gone by ps -ef | grep defunct


References


Top comments (1)

Collapse
 
natnaelsisay profile image
Natnael Sisay

I found this article really useful. With its clear and on point explanation, and it helped me solve the issue i had. Thank you