What is a broken process on Linux

What are zombie processes on Linux and how can you kill them?

Zombie trial. Not everyone has heard of this interesting but scary word referring to the Linux operating system. On a PC, zombie processes may not pose a threat to a normal user. However, on Linux servers, these processes must be identified and stopped.

Such processes can cause problems with your system's process table and in turn affect the proper functioning of your machine. Hence, in this article, we are going to cover zombie processes in depth, as well as a comprehensive guide on how to find and kill zombie processes on a Linux computer.

What are zombie trials?

Most of all, it is important that you know what zombie processes really are. These are nothing more than dead and broken processes that are taking up space in the system process table. A process control block or circuit board is a data structure that stores details about individual processes running on your system.

The process table consists of the process ID, a link to the circuit board, and other useful information about the process. Zombie processes have their own process IDs and memory management information. Since there are only a limited number of process IDs available for the Linux operating system, other processes cannot use the PIDs until the zombie process has stopped.

Although one or two zombie processes will not cause glitches or performance problems on your computer, a large number of such processes can affect the workflow of your system by flooding the process table and resources.

What causes zombie processes on Linux?

To understand the underlying cause of a zombie process in detail, you need to learn how to start and stop processes on Linux. The Linux operating system monitors all running processes and daemons on a computer. The Process table is a list of structures that contains all of the processes currently running on your computer.

Each process entry in the process table consists of a link to the Process control block this particular process. The circuit board stores the details associated with that particular process. These details include:

  1. Process status : The current status of the process
  2. Process number: unique number used to identify the process
  3. Program counter : Contains information about the next instruction
  4. register : List of all CPU registers used by the process
  5. Open file list : Files used by the process
  6. CPU planning information : Contains information about the CPU time and the resources allocated to the process
  7. Storage management information : Provides details of the amount of memory used by the process
  8. I / O information : List of input or output devices used by the process

Linux uses the following process states to describe all of its processes.

  • R. : Process is running
  • S. : Sleep process
  • D. : Uninterrupted sleep process
  • T : Process ended
  • Z : Zombie trial

Whenever a process completes the assigned task, its process status is shown as a zombie or Z set . Each process has a parent process that is a family of functions called wait () that waits for the status of a process to change. For example, if the process status of " To run" in " Zombie" changes, the method becomes wait () triggered.

The wait () Method normally deletes the process control block related to this zombie process and then removes the entry of this process from the process table.

Because of the poor development of a program, the higher-level process sometimes calls the function wait () Not on . As a result, the system does not erase the zombie process circuit board. The process table entry for that particular process is also retained.

This grants the zombie process an infinite lifespan. Since the system cannot kill the process, the process entry is never deleted and the PID is never released.

More information: Ways to End Unresponsive Programs on Linux

How do I find zombie processes?

The first step in removing zombie processes from your system is to analyze which process is causing the Zombie- Has process status. While you cannot terminate these processes directly because the system has already removed them from memory, you can terminate the parent process associated with them.

First, you need to check if your system's process table contains a zombie process. You can easily do this with the command Top to do. Just open your terminal and type:

You will see output similar to this one. Notice the number of zombie processes at the top of the terminal window. If the output is zero then there is nothing to worry about.

You can list information about these zombie processes by using the ps command with forward egrep . Egrep is an extension of the grep command on Linux that treats all patterns as an extended regex string.

Related: The Beginner's Guide to Regular Expressions Using Python

Enter the following command to list all zombie processes:

The aforementioned command will search for lines that are either Z or deleted included in the output generated by the ps command. The output consists of a list of the zombie processes running on your system.

Killing zombie processes with the kill command

Now that you know which zombie processes are currently consuming your system resources, it is time to kill those processes.

While the easiest way to end zombie processes is to restart your computer, sometimes it isn't a viable option, especially if you are managing a server.

To kill zombie processes without shutting down your server, write down the process ID of a zombie process. From the previous section we can see that the PID of the zombie process was 18614. Then use this PID to determine the ID of the parent process.

Output:

Check with the command ps, whether the parent process ID is available.

Now that we have confirmed the existence of the parent process, it is time to end it. Hand over the -SIGKILL- Flag with the command kill as follows:

Once you finish the parent process, the system will delete the zombie process and automatically remove it from the process table.

Efficient management of processes under Linux

Every system administrator must prioritize monitoring processes running on a Linux computer. While zombie processes are not necessarily harmful to your system, they can cause performance problems if they are present in large numbers.

If you are a novice Linux user and have no idea how the Linux operating system manages processes, learning what processes are first is a good place to start.