Atlantic.Net Blog

How to Kill Running Processes in Linux

Hitesh Jethva
by Atlantic.Net (395 posts) under Tutorials, VPS Hosting
0 Comments

In Linux, an instance of a running service, application, or script is called a process. When you run any command, program, or application, a process is created for it. Each process has its own process id that is associated with a specific user and group. If any processes consume too many resources or become unresponsive, then you may need to kill them. In this case, you can use the kill command to stop the process without restarting your server.

In this post, we will show you how to kill running processes in Linux.

Prerequisites

  • A server running Linux on the Atlantic.Net Cloud Platform
  • A root password configured on your server

Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing any Linux operating system with at least 1GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

View Running Processes in Linux

The simplest and easiest way to get a list of all running processes is to use the top command. You can run the top command as shown below to list all running processes:

top

You will get all running processes in the following output:

Tasks: 344 total,   1 running, 297 sleeping,   0 stopped,   0 zombie
%Cpu(s): 22.6 us,  6.0 sy,  0.1 ni, 67.1 id,  3.9 wa,  0.0 hi,  0.4 si,  0.0 st
KiB Mem :  7580260 total,  2103076 free,  3174408 used,  2302776 buff/cache
KiB Swap:  2097148 total,  2097148 free,        0 used.  3901388 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                   
 5994 vyom      20   0   44344   4160   3444 R  11.8  0.1   0:00.03 top                                                                       
 2206 vyom      20   0 1046476  89792  60368 S   5.9  1.2   1:15.26 Xorg                                                                      
 2359 vyom      20   0 3471324 216412  97596 S   5.9  2.9   1:58.27 gnome-shell                                                               
 2745 vyom      20   0 1776552 136144  99424 S   5.9  1.8   1:09.93 skypeforlinux                                                             
 2775 vyom      20   0 37.371g 169524 117660 S   5.9  2.2   1:05.09 skypeforlinux                                                             
 5655 root      20   0       0      0      0 I   5.9  0.0   0:00.30 kworker/u8:3-ev                                                           
    1 root      20   0  160356   9464   6632 S   0.0  0.1   0:03.50 systemd                                                                   
    2 root      20   0       0      0      0 S   0.0  0.0   0:00.00 kthreadd                                                                  
    3 root       0 -20       0      0      0 I   0.0  0.0   0:00.00 rcu_gp                                                                    
    4 root       0 -20       0      0      0 I   0.0  0.0   0:00.00 rcu_par_gp                                                                
    6 root       0 -20       0      0      0 I   0.0  0.0   0:00.00 kworker/0:0H-kb                                                           
    9 root       0 -20       0      0      0 I   0.0  0.0   0:00.00 mm_percpu_wq                                                              
   10 root      20   0       0      0      0 S   0.0  0.0   0:00.40 ksoftirqd/0                                                               
   11 root      20   0       0      0      0 I   0.0  0.0   0:03.58 rcu_sched                                                                 
   12 root      rt   0       0      0      0 S   0.0  0.0   0:00.01 migration/0                                                               
   13 root     -51   0       0      0      0 S   0.0  0.0   0:00.00 idle_inject/0                                                             
   14 root      20   0       0      0      0 S   0.0  0.0   0:00.00 cpuhp/0                                                                   
   15 root      20   0       0      0      0 S   0.0  0.0   0:00.00 cpuhp/1                                                                   
   16 root     -51   0       0      0      0 S   0.0  0.0   0:00.00 idle_inject/1                                                             

You can press k and enter the process ID to kill the process directly from the top interface.

Find the Process Using the ps Command

ps is a command-line utility that will display a complete listing of running processes in the specified format.

The basic syntax of the ps command is shown below:

ps [OPTION]

A brief explanation of each option is shown below:

  • -a – Display running processes of all users.
  • -u – Display detailed information about each of the processes.
  • -x – Display processes that are controlled by the daemon.

For example, run the following command to get a detailed process list of all processes.

ps aux

You will get the following output:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.1  0.1 160356  9464 ?        Ss   15:51   0:03 /sbin/init splash
root         2  0.0  0.0      0     0 ?        S    15:51   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        I<   15:51   0:00 [rcu_gp]
root         4  0.0  0.0      0     0 ?        I<   15:51   0:00 [rcu_par_gp]
root         6  0.0  0.0      0     0 ?        I<   15:51   0:00 [kworker/0:0H-kb]
root         9  0.0  0.0      0     0 ?        I<   15:51   0:00 [mm_percpu_wq]
root        10  0.0  0.0      0     0 ?        S    15:51   0:00 [ksoftirqd/0]
root        11  0.1  0.0      0     0 ?        I    15:51   0:03 [rcu_sched]
root        12  0.0  0.0      0     0 ?        S    15:51   0:00 [migration/0]
root        13  0.0  0.0      0     0 ?        S    15:51   0:00 [idle_inject/0]
root        14  0.0  0.0      0     0 ?        S    15:51   0:00 [cpuhp/0]
root        15  0.0  0.0      0     0 ?        S    15:51   0:00 [cpuhp/1]
root        16  0.0  0.0      0     0 ?        S    15:51   0:00 [idle_inject/1]
root        17  0.0  0.0      0     0 ?        S    15:51   0:00 [migration/1]
root        18  0.0  0.0      0     0 ?        S    15:51   0:00 [ksoftirqd/1]
root        20  0.0  0.0      0     0 ?        I<   15:51   0:00 [kworker/1:0H-kb]
root        21  0.0  0.0      0     0 ?        S    15:51   0:00 [kdevtmpfs]
root        22  0.0  0.0      0     0 ?        I<   15:51   0:00 [netns]

The above command will show you all the running processes. You can use the grep command with the ps command to get a PID of a specific process.

For example, to get a PID of an Apache process, run the following command:

ps aux | grep apache

You will get the following output:

root      1309  0.0  0.0  73992  4748 ?        Ss   15:52   0:00 /usr/sbin/apache2 -k start
www-data  1310  0.0  0.0 1285068 4620 ?        Sl   15:52   0:00 /usr/sbin/apache2 -k start
www-data  1311  0.0  0.0 1285068 4644 ?        Sl   15:52   0:00 /usr/sbin/apache2 -k start

You can also use the pidof command to get a PID of a specific process.

pidof apache2

You will get the following output:

1311 1310 1309

Kill a Process in Linux

At this point, you know how to get the PID of any process. Now, you can use the kill command to kill a running process.

To kill a single process, run the following command:

kill PID

Or

kill -9 PID

To kill multiple processes, run the following command:

kill -9 PID1 PID2 PID3

You can also kill the processes by their names. You can use the pkill command to kill a process by its name.

To kill the Apache process, run the following command:

pkill apache2

You can also use the killall command to kill a process by its name:

killall mysqld

Conclusion

In this post, we explained how to find and kill a process in Linux. You can now kill any unresponsive processes by yourself without restarting your server. Try it on VPS hosting from Atlantic.Net!

Get A Free To Use Cloud VPS

Free Tier Includes:
G3.2GB Cloud VPS Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

How to Install Apache Solr on Oracle Linux 8
How to Install Apache Cassandra on Oracle Linux 8
How to Install Yarn NPM Package Manager on Oracle Linux 8
How to Install Apache Spark on Oracle Linux 8
How to Install Docker and Docker Compose on Oracle Linux 8

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2008 Lookout Dr,

Dallas, Texas 75044

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources