How to forcefully stop and kill a process in Linux

There are times when a process hangs or is responding very late when you feel like killing the process. The ultimate solution is to find the process id of the respective process and kill the same but below list of steps can also be used.

 

How to forcefully stop a process?

You can use "Ctrl + Z" to forcefully stop a process as used below

# yum whatprovides */python-deltarpm
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Repository RHEL is listed more than once in the configuration
RHEL                                                   | 2.9 kB  00:00:00
RHEL/primary_db                                        | 3.7 kB  00:00:00
RHEL/filelists_db                                      | 2.2 kB  00:00:00
No matches found
^Z
[1]+  Stopped                 yum whatprovides */python-deltarpm
Now stopping this way does not means that the process is killed. If I see list of process
# ps aux | grep -i yum
root     10511  2.8  1.7 422324 71476 pts/2    T    19:09   0:00 /usr/bin/python /usr/bin/yum whatprovides */python-deltarpm

Here as we see the stat shows "T" which means stopped.

 

How do we list stopped processes?

By executing "jobs" command as below

# jobs
[1]+  Stopped                 yum whatprovides */python-deltarpm

This command will list you all the process which are in stopped state

 

How to kill a stopped process?

Here we need to use the identifier which is assigned to each stopped process. Here in our case as we see the identifier is [1]

So the command to kill this particular process would be

# kill %1
[1]+  Stopped                 yum whatprovides */python-deltarpm

Immediately now if I try to see the list of available stopped processes

# jobs
[1]+  Exit 1                  yum whatprovides */python-deltarpm

Here now it is trying to Exit as we see above

Again after few seconds if I give the same command

# jobs

No output so I do not have any stopped processes

I hope this article was useful.

Related Articles

Leave a Comment