12
orhun
27d

zps: A small utility for listing and reaping zombie processes on GNU/Linux.

Project Type
Existing open source project
Summary

zps: A small utility for listing and reaping zombie processes on GNU/Linux.

Description
On Unix and Unix-like computer operating systems, a zombie process or defunct process is a process that has completed execution (via the exit system call) but still has an entry in the process table. This occurs for child processes, where the entry is still needed to allow the parent process to read its child's exit status: once the exit status is read via the wait system call, the zombie's entry is removed from the process table and it is said to be "reaped". Unlike the normal processes, zombie processes cannot be removed from a system with the kill command since they are already dead. (This is where the term's metaphor [zombie - an undead person] comes from.) To reap a zombie process, SIGCHLD signal can be sent to the parent process manually using the kill command. If the parent process refuses to reap the zombie, then terminating the parent process (mostly with SIGTERM signal) can be an option. When a child process loses its parent, init process becomes its new parent and it will reap any zombies since it executes the wait system call periodically. Zombie processes are not harmful since they are not affecting other processes or using any system resources. However, they do retain their process ID. This can lead to preventing new processes to launch if all the available PIDs were assigned to zombie processes. Considering Unix-like systems have a finite number of process IDs, it's one of the problems that zombie processes can cause. Another danger of zombie processes is that they can cause resource leak if they stay as a zombie in the process table for a long time. Apart from these issues, having a few zombie processes won't be a big deal for the system although they might indicate a bug with their parent process. zps aims to list the running processes at a particular time with stats and indicate the zombie processes on this list. It can also reap these zombie processes automatically if --reap argument is provided. There's also --xreap argument for reaping zombie processes after listing. Technically, zps reads process stats from /proc filesystem and uses C POSIX library to handle listing, sending signals and other operations.
Tech Stack
C
Current Team Size
1
URL
Comments
  • 1
    I'm interested. How do you propose collecting that exit code?
  • 0
    @netikras zps checks '/proc/<pid>/stat' file for indicating zombies. So I'm not dealing with exit codes at all.
  • 0
    @orhun No.
    zps utility is there to do 2 things:
    1) find and list all the zombies;
    2) clear them from the process table.

    zps already does #1 as far as I see from the code. I do not see it doing #2 yet. How do you propose should it be done?
  • 1
    @orhun My bad.. it already does #2. Did not see that part in my phone screen. My appologies

    if(!kill(defunctProcs[i].ppid, SIGTERM)) {

    My GOD! So does it mean it will kill mi `init` process? Am I reading this right?
  • 0
    @netikras Yes, at least for now. I'll change this signal to SIGCHLD but I have to add an extra check for it if I do this.
  • 0
    Oh, and one more thing.
    It CAN kill your init process but I don't think it will happen. Seems not possible.
Add Comment