[article/tutorial] How to Kill Zombie Processes on Linux

3 messages · started by Devi Garcia on Nov 26, 2020

[article/tutorial] How to Kill Zombie Processes on Linux

From Devi Garcia · Nov 26, 2020

Programs that are poorly written or performing badly can leave zombie processes lurking inside your Linux computer. Find out how zombies are created, and how you can finally lay them to rest.

How Process States Work on Linux

Linux, of course, has to keep track of all the applications and daemons running on your computer. One of the ways it does this is by maintaining the process table. This is a list of structures in kernel memory. Each process has an entry in this list that contains some information about it.

There isn’t a great deal in each of the process table structures. They hold the process ID, a few other data items, and a pointer to the process control block (PCB) for that process.

It’s the PCB that holds the many details Linux needs to look up or set for each process. The PCB is also updated as a process is created, given processing time, and finally destroyed.

The Linux PCB contains over 95 fields. It’s defined as a structure called task_struct.h, and it’s over 700 lines long. The PCB contains the following types of information:

  • Process State: The states are described below.
  • Process Number: Its unique identifier within the operating system.
  • Program Counter: When this process is next given access to the CPU, the system will use this address to find the next instruction of the process that should be executed.
  • Registers: The list of CPU registers used by this process. The list might contain accumulators, index registers, and stack pointers.
  • Open File List: Files associated with this process.
  • CPU Scheduling Information: Used to determine how frequently, and for how long, CPU processing time is awarded to this process. The priority of the process, pointers to scheduling queues, and other scheduling parameters have to be recorded in the PCB.
  • Memory Management Information: Details about the memory this process is using, such as the start and end addresses of the process memory, and pointers to the memory pages.
  • I/O Status Information: Any in- or output devices used by the process.

The “Process State” can be any of the following:

  • R: A running or runnable process. Running meaning it’s receiving CPU cycles and executing. A runnable process is ready to run and waiting for a CPU slot.
  • S: A sleeping process. The process is waiting for an action to complete, such as an in- or output operation, or for a resource to become available.
  • D: The process is in an uninterruptible sleep state. It’s using a blocking system call and can’t continue until the system calls have completed. Unlike the “Sleep” state, a process in this state won’t respond to signals until the system call is completed and execution has returned to the process.
  • T: The process has terminated (stopped) because it received the SIGSTOP signal. It will only respond to the SIGKILL or SIGCONT signals, which either kill the process or instruct it to continue, respectively. This is what’s happening when you swap from foreground (fg) to background (bg) tasks.
  • Z: A Zombie process. When a process completes, it doesn’t just vanish. It frees up any memory it’s using and removes itself from memory, but its entry in the process table and PCB remain. Its state is set to EXIT_ZOMBIE, and its parent process is notified (by the SIGCHLD signal) that the child process has finished.

View original on FreeLists

[article/tutorial] How to Kill Zombie Processes on Linux

From Devi Garcia · Nov 26, 2020

Programs that are poorly written or performing badly can leave zombie processes lurking inside your Linux computer. Find out how zombies are created, and how you can finally lay them to rest.

How Process States Work on Linux

Linux, of course, has to keep track of all the applications and daemons running on your computer. One of the ways it does this is by maintaining the process table. This is a list of structures in kernel memory. Each process has an entry in this list that contains some information about it.

There isn’t a great deal in each of the process table structures. They hold the process ID, a few other data items, and a pointer to the process control block (PCB) for that process.

It’s the PCB that holds the many details Linux needs to look up or set for each process. The PCB is also updated as a process is created, given processing time, and finally destroyed.

The Linux PCB contains over 95 fields. It’s defined as a structure called task_struct.h, and it’s over 700 lines long. The PCB contains the following types of information:

  • Process State: The states are described below.
  • Process Number: Its unique identifier within the operating system.
  • Program Counter: When this process is next given access to the CPU, the system will use this address to find the next instruction of the process that should be executed.
  • Registers: The list of CPU registers used by this process. The list might contain accumulators, index registers, and stack pointers.
  • Open File List: Files associated with this process.
  • CPU Scheduling Information: Used to determine how frequently, and for how long, CPU processing time is awarded to this process. The priority of the process, pointers to scheduling queues, and other scheduling parameters have to be recorded in the PCB.
  • Memory Management Information: Details about the memory this process is using, such as the start and end addresses of the process memory, and pointers to the memory pages.
  • I/O Status Information: Any in- or output devices used by the process.

The “Process State” can be any of the following:

  • R: A running or runnable process. Running meaning it’s receiving CPU cycles and executing. A runnable process is ready to run and waiting for a CPU slot.
  • S: A sleeping process. The process is waiting for an action to complete, such as an in- or output operation, or for a resource to become available.
  • D: The process is in an uninterruptible sleep state. It’s using a blocking system call and can’t continue until the system calls have completed. Unlike the “Sleep” state, a process in this state won’t respond to signals until the system call is completed and execution has returned to the process.
  • T: The process has terminated (stopped) because it received the SIGSTOP signal. It will only respond to the SIGKILL or SIGCONT signals, which either kill the process or instruct it to continue, respectively. This is what’s happening when you swap from foreground (fg) to background (bg) tasks.
  • Z: A Zombie process. When a process completes, it doesn’t just vanish. It frees up any memory it’s using and removes itself from memory, but its entry in the process table and PCB remain. Its state is set to EXIT_ZOMBIE, and its parent process is notified (by the SIGCHLD signal) that the child process has finished.

View original on FreeLists

Re: [article/tutorial] How to Kill Zombie Processes on Linux

From George Praggastis · Nov 28, 2020

thks david very interesting...seems ps can do everything regarding processes except cook breakfast.

On Thu, Nov 26, 2020 at 10:25 AM Devi Garcia <asphyxiated.god@gmail.com> wrote:
Quoted reply (21 lines)
Programs that are poorly written or performing badly can leave  zombie processes  lurking inside your Linux computer. Find out how zombies are created, and how you can finally lay them to rest.
How Process States Work on Linux
Linux, of course, has to keep track of all the applications and daemons running on your computer. One of the ways it does this is by maintaining the process table. This is a list of structures in kernel memory. Each process has an entry in this list that contains some information about it.

Programs that are poorly written or performing badly can leave zombie processes lurking inside your Linux computer. Find out how zombies are created, and how you can finally lay them to rest.

How Process States Work on Linux

Linux, of course, has to keep track of all the applications and daemons running on your computer. One of the ways it does this is by maintaining the process table. This is a list of structures in kernel memory. Each process has an entry in this list that contains some information about it.

There isn’t a great deal in each of the process table structures. They hold the process ID, a few other data items, and a pointer to the process control block (PCB) for that process.

It’s the PCB that holds the many details Linux needs to look up or set for each process. The PCB is also updated as a process is created, given processing time, and finally destroyed.

The Linux PCB contains over 95 fields. It’s defined as a structure called task_struct.h, and it’s over 700 lines long. The PCB contains the following types of information:

  • Process State: The states are described below.
  • Process Number: Its unique identifier within the operating system.
  • Program Counter: When this process is next given access to the CPU, the system will use this address to find the next instruction of the process that should be executed.
  • Registers: The list of CPU registers used by this process. The list might contain accumulators, index registers, and stack pointers.
  • Open File List: Files associated with this process.
  • CPU Scheduling Information: Used to determine how frequently, and for how long, CPU processing time is awarded to this process. The priority of the process, pointers to scheduling queues, and other scheduling parameters have to be recorded in the PCB.
  • Memory Management Information: Details about the memory this process is using, such as the start and end addresses of the process memory, and pointers to the memory pages.
  • I/O Status Information: Any in- or output devices used by the process.

The “Process State” can be any of the following:

  • R: A running or runnable process. Running meaning it’s receiving CPU cycles and executing. A runnable process is ready to run and waiting for a CPU slot.
  • S: A sleeping process. The process is waiting for an action to complete, such as an in- or output operation, or for a resource to become available.
  • D: The process is in an uninterruptible sleep state. It’s using a blocking system call and can’t continue until the system calls have completed. Unlike the “Sleep” state, a process in this state won’t respond to signals until the system call is completed and execution has returned to the process.
  • T: The process has terminated (stopped) because it received the SIGSTOP signal. It will only respond to the SIGKILL or SIGCONT signals, which either kill the process or instruct it to continue, respectively. This is what’s happening when you swap from foreground (fg) to background (bg) tasks.
  • Z: A Zombie process. When a process completes, it doesn’t just vanish. It frees up any memory it’s using and removes itself from memory, but its entry in the process table and PCB remain. Its state is set to EXIT_ZOMBIE, and its parent process is notified (by the SIGCHLD signal) that the child process has finished.


--
Have a good day...George

View original on FreeLists


Previous thread · Next thread

Back to November 2020