What are different Process states in Linux!

What is a Zombie Process!

How to Clean a Linux Zombie Process!

A Thread 👇 PC: https://store-images.s-microsoft.com
What Is a Zombie Process?

Zombie processes in Linux are sometimes also referred to as defunct or dead processes. They’re processes that have completed their execution, but their entries are not removed from the process table. PC: https://totozhang.github.io/
What are different Process States?

Linux maintains a process table of all the processes running, along with their states. Let’s briefly overview the various process states: PC: https://miro.medium.com/max/642/1*IaPYYJt9tXFvDnLeWNuVbw
Running (R): These processes are currently running or runnable.
Waiting (S/D): These are the processes that are waiting for an event or a resource. The wait can either be an interruptible sleep (S) or an uninterruptible sleep (D).
Stopped (T): We can stop a Linux process by sending an appropriate signal.
Zombie (Z): When a process finishes its task, it releases the system resources it was using and cleans up its memory. However, its entry from the process table is not removed, and its status is set as EXIT_ZOMBIE.
How Zombie Processes gets created?

When a process completes its job, the Linux kernel notifies the exiting process’s parent by sending the SIGCHLD signal. The parent then executes the wait() system call to read the status of the child process and reads its exit code.
This also cleans up the entry of the child process from the process table, and hence, the process finishes.

However, if a parent process isn’t programmed to execute the wait() system call on the creation of the child process, proper cleanup doesn’t happen.
In such cases, the parent process cant monitor the state changes of the child processes, and eventually, it ignores the SIGCHLD signal. This causes the zombie state of the finished process to stay in the process table, and hence it appears in the process list as a zombie process.
Another case of interest is when a parent process is unable to handle or receive the SIGCHLD signal from the child process. Such cases also lead to zombie creation.
How to Identify Zombie Processes?

We can identify the list of zombies using the ps command:

As observed from the output, the Z in the STAT column or zombie or <defunct> pattern from the output of the ps command can be used to identify the zombies.

$ ps aux | egrep "Z|defunct" PC: https://www.howtogeek.com/wp-content/uploads/2020/11/3-2
We can find out Z process state using the awk command as well:

$ ps ux | awk '{if($8=="Z") print}'
How to clean a Zombie Process?

You can’t really kill a zombie process since it’s already dead. However, there are a few workarounds we can use to clean up a zombie process.
Method 1 -
Using SIGCHLD Signal -

We can manually send the SIGCHLD signal to d parent of a zombie process. Consequently, it'll intimate d parent to trigger d wait() system call, which will clean up d defunct child process from d process table.
Let’s find d parent id of our defunct process:
$ ps -A -ostat,pid,ppid | grep -e '[zZ]'

Next, let’s send the SIGCHLD signal to d parent process using d kill cmd:

$ kill -s SIGCHLD 103
However, it isn’t really guaranteed that sending the SIGCHLD signal to the parent will kill a zombie process. It works only in cases where parent processes can handle the SIGCHLD signals.
Method 2 -
Killing d Parent Process -

If d method discussed in d previous section is unable to clear d defunct process, we should consider killing its parent process:

$ kill -9 103

Here, 103 is the parent id of our defunct process with PID 108.
However, killing a parent can affect all its childs. Hence, we shud exercise extra caution & must identify d impact before killing a parent process.

If der are a lot of Z processes,or if d parent of d Z process is d init process (with pid=1),we can also consider a system reboot.
Retweet if you liked the thread. Follow me for more such content.

PC: baeldung

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Rakesh Jain

Rakesh Jain Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @devops_tech

30 Nov
What is systemd and why should Linux users care about it?

Everything about "systemd" !!

A Mega Thread 👇 https://everyday.codes/
What is systemd ?

systemd is the glue that holds Linux systems together. systemd is a collection of building blocks, which handle services, processes, logging, network connectivity and even authentication. PC: https://images.techhive.com/ & ZDNet
systemd handles the boot process for Linux systems. As an init implementation, it has a PID of 1 like other init systems, such as System V, Upstart.

It was designed as a replacement for SystemV and LSB-style startup scrips, which were prevalent since 1980s.
Read 44 tweets
19 Nov
#Linux Boot Process Explained!

A Thread 👇 PC: https://images.wallpapersden.com/
Every Linux Admin or DevOps Engineer should know what happens when a Linux system boots. It's a very popular Interview Question as well.
Every time you power on your Linux PC, it goes through a series of stages before finally displaying a login screen that prompts for your username or password.

There are 3 high level stages of a typical Linux boot process.
Read 20 tweets
29 Oct
Everything you need to know about Virtualization, VMs , Containers, Pods, Clusters ..

A Mega Thread 👇 PC: production-cci-com.imgix.net
What is Virtualization?

Virtualization is the act of dividing shared computational resources: CPU, RAM, Disk, and Networking into isolated resources that are unaware of the original shared scope. PC: cloud4y
What is a virtual machine?

A VM is a virtual env that functions as a virtual computer system with its own CPU, memory, nw interface, & storage, created on a physical hw system (located off- or on-prem).

It uses sw instead of a physical computer to run programs & deploy apps. PC: nakivo
Read 26 tweets
27 Oct
Traceroute: A computer Network Diagnostic Tool 🛠️

How does it work! 🤔

Ping works fine but not traceroute! 🤨

What are the stars in traceroute output! *⃣*⃣*⃣

#Linux #Networking

A Thread 👇 PC: n-able.com
What is traceroute ?

traceroute tracks the route packets take across an IP network on their way to a given host.

It assists you in troubleshooting nw connectivity issues from your Destination to a Remote destination by using echo packets (ICMP) to visually trace the route.
The syntax -

The cmd traceroute <x> (x here being an IP or hostname) is d most basic version & it will begin to send packets to d designated target. This result will allow u to trace d path of d packets sent from ur machine to each of d systems b/n u & ur desired destination.
Read 22 tweets
25 Oct
Cyber Security Basics!

#infosec

A Mega Thread 👇 PC: cyberoregon
What is Cyber Security?

Cybersecurity is a way of protecting the network, computers, and other electronic gadgets from cybercriminals. The Malicious attackers might delete, modify or leak confidential information posing a huge threat to a business or an individual. PC: abacustechnologies
What is Cyber Crime?

Here are some examples of Cyber Crime:

1. Identity Theft

2. Online Predators

3. BEC ("Business Email Compromise")

4. Ransomware

4. Stealing of sensitive intellectual property
Read 33 tweets
22 Oct
What is Kubernetes and How it works!

A Short Thread 👇👇 Image
Use case ->

You have created an application and want to share it with the world. Image
Docker comes into the picture to package the application. Image
Read 10 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(