Why zombie process disappears from htop if i don't call waitpid()?

Viewed 373
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

int main()
{
        int pid = fork();
        if (pid == 0)
        {
                printf("I am Child\n");
                exit(0);
        }
        printf("I am Parent\n");
        while(1);
}

Here is what happens on my Linux when i run this code: zombie process shows up in htop for a second and then just disappears. I tried setting signal handler in parent:

void callback(int signum)
{
    return;
}

int main()
{
        int pid = fork();
        if (pid == 0)
        {
                printf("I am Child\n");
                exit(0);
        }
        printf("I am Parent\n");
        signal(SIGCHLD, callback);
        while(1);
}

But nothing changed. Why my zombie process disappears from htop?

P.S.: compiled with no optimization

Update: it doesn't show up in htop but does show up in top. Seems like a bug to me. I vote for deletion of this question.

1 Answers

The process disappears from htop because by default it sorts by CPU usage, so a zombie process will be so far down the list that it's off the screen.

It happens after one second because that's the default htop refresh interval.

Related