How to kill the sleeping process in ubuntu


I want to clear the process which state Z, but the parent process ID is sleeping (S) State.

How to clear the Sleeping process which is will impact anything because this needs to be done in ruby application.

Could anyone please give a suggestion to this thanks in advance.


Hi for brief just follow the below command to find sleeping (S), zombie (Z), uninterruptible sleep (D) processes on Linux:

# ps axo stat,ppid,pid,comm | grep -w defunct    ###for Zombie Process

# ps axo stat,ppid,pid,comm | grep -w "D"        ###for Uninterruptible Pro

# ps axo stat,ppid,pid,comm | grep -w "S"        ###for Sleeping Pro 

using the below command you can kill the processes

Note that the above command gives you PPID (parent process ID) of each zombie.

# pkill -9 pid

If still the processes exists then kill the parent process

List the PID of Zombie…?

# ps aux | awk '{ print $8 " " $2 }' | grep -w 'Z' 

In order to kill these processes, you need to find the parent process first.

# pstree -paul


# kill -9 ppid

No need to bother about the sleeping process if you find any zombie or D state process you can kill them by using above commands.

thanks @raghuu if we kill the sleeping process means what will happen because am worried is there any impact … ?


You are not supposed to kill the sleeping processes, let me explain in brief what a sleeping process is

Suppose a process starts: it gets loaded into memory, so some memory has to be allocated to it. It also gets some processor time, otherwise it would lurk just there, unable to run. Now it starts and probably it will need some additional memory to hold runtime data, it might need other OS resources, like files to be opened, network connections to be established, etc., etc…

All these requests involve the OS, which may or may not be able to fulfill these immediately. If fulfilled, the process gets what it requests, but if not it will be put to sleep until the OS can provide.

That it is put to sleep does not mean it has nothing to do or that it could be stopped. This is just a way for the OS to do something else until it can provide everything necessary to run the process.

Another possibility is that the process waits for a certain event: suppose the process services a certain network event: it will listen to the network and until a certain signal comes it has nothing to do - therefore it is going to sleep. When the signal comes, it wakes up, does whatever it is supposed to do, then goes back to sleep again. If you stop the process because it sleeps it will not be able to wake up once the signal comes.

Start mc in a terminal, open a new terminal and start the commands below

kill -STOP $(pgrep mc)
ps o pid,state,command |
awk ’ {if ($2 == “T”) {printf “%s\t%s\t%s\n”,“Sleeping”,$1,$3};}’
Output is

Sleeping 21668 mc