Linux-based operating systems, like all other operating systems, have processes and services that run while the machine is on. These range from various operating system services, to the command line, to different services/daemons designed to maintain the system and keep it running smoothly. Most services are vital to a process’ normal operation, ranging from helper services, to special services designed to handle input, improve performance, offload resources, etc. Processes are also the backbone of a computer’s core functionality, making it important to have the resources for them all.
However, it may occur that a service can run without your knowledge, use up system resources, and even make your system vulnerable if security measures have not been taken into account. Because of possible cases like these, it’s good to know how to check and deal with such cases, as well as have the ability to monitor what processes and services are running on your machine at any moment.
In this tutorial, we will go through several methods of listing/showing all running services and processes on a Linux-based server or machine, as well as go through some useful commands that will help you find and manage these processes and services.
The ‘service’ command line tool
The ‘service’ command comes pre-installed with almost every Linux distribution out there. While it’s main purpose is to start and stop scripts and create processes, ‘service’ can also be used to see what services are running or stopped at any given moment. Using a simple command, we are given a complete list of services:
When you run this, an output similar to this will appear:
[ + ] apache-htcacheclean [ + ] apache2 [ + ] apparmor [ + ] bind9 [ - ] bluetooth [ - ] bootmisc.sh [ - ] cgmanager [ - ] cgproxy [ - ] checkfs.sh [ - ] checkroot-bootclean.sh [ - ] checkroot.sh (continued)
As you can see, a list of services are given as output, with a symbol to the left of the service’s name. A ‘+’ symbol means the service is running, a ‘-‘ means that it is stopped, and a ‘?’ means that the status is not currently known. When this is used in combination with a search tool such as ‘grep’, finding specific services that are running is very easy to do. You can then check the status on a process-by-process basis by entering the status command for a specific process:
service <service name> status
This will then output a set of information pertaining to that specific service, including the location of the process, whether or not the service is running, and even the last few lines of the log file from the service.
Short for ‘process status’, PS is a pre-installed utility designed to display information and details about processes. It is a simple, fast tool designed to give quick results with no fuss. With one simple command, we can list a well-detailed list of currently running processes:
You can use this in conjunction with the ‘less’ command to further improve readability. When running this command, we are given details for each process currently running. You can also use the ‘grep’ command to narrow down the results to a specific process name, process ID, and so on.
The ‘top’ command line tool
‘top’ is a built-in tool designed to give an overview of all processes and services currently running on your machine. It is included on both Debian-based and RedHat-based distributions, and offers a variety of features to help you figure out what’s happening on your server. You can start ‘top’ by simply writing top on the command line. This is what it should look like:
top - 03:29:24 up 53 min, 1 user, load average: 0.00, 0.00, 0.00 Tasks: 58 total, 1 running, 57 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.2 us, 0.0 sy, 0.0 ni, 99.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 2097152 total, 1025376 free, 504424 used, 567352 buff/cache KiB Swap: 0 total, 0 free, 0 used. 1485816 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1073 root 20 0 128404 1672 888 S 0.3 0.1 0:00.45 screen 3160 root 20 0 157900 2156 1516 R 0.3 0.1 0:00.06 top 1 root 20 0 129484 3716 2412 S 0.0 0.2 0:03.03 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd/2306 3 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khelper/2306 57 root 20 0 39176 2816 2492 S 0.0 0.1 0:00.53 systemd-journal 63 root 20 0 42624 1740 1292 S 0.0 0.1 0:00.01 systemd-udevd (continued)
It can look a bit cluttered, but a lot of this information is very useful. For example, we can see how long the system has been running, the average load, how many users are logged in, how many processes (tasks) are running, sleeping, etc. as well as info on the amount of memory we have total and available on the server. Top goes into even greater detail, down to a process-specific level. Each column displays a specific value that correlates with the process that is running. We can see who owns the process, how much memory it’s utilizing, how much of the CPU is being utilized, the command name, and the process ID, which is unique to that process and helps us identify it in case there’s more than one of the same process. Using all of this information, we can see exactly what each process is doing, and how many resources each process uses up, all in real time.
Htop is a lot like ‘top’ in terms of its core features and functionality. It is not usually included in a default operating system install, however it is available for most if not all Linux distributions through its pre-installed software repositories. Like top, htop allows the user to view detailed information about each process, as well as keep tabs on the system itself. However, htop allows for much finer control over the information displayed to you, as well as offering a suite of utilities that can be applied to processes.
For example, through htop, you can adjust the niceness (the priority) of a process, kill it with varying levels of force, and so on. There’s also sorting, which makes it easier to see only the information that is important to you. Selecting process is possible using the space bar, making it easier to follow and keep track of a specific process (or processes, since you can select more than one at a time). And with a search function, it’s even easier to check and pay attention to specific processes. Htop even has a bar chart that represents the various system resources, allowing you to easily see how much CPU or RAM is allocated.
Here’s an example of what htop looks like:
1 [ 0.0%] Tasks: 35, 113 thr; 1 running 2 [|| 1.3%] Load average: 0.01 0.05 0.01 Mem[||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 799M/2.00G] Uptime: 4 days, 22:53:28 Swp[ 0K/0K] PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command 9357 mysql 20 0 1625M 196M 1944 S 0.7 9.6 4:54.66 /usr/sbin/mysqld 26708 root 20 0 26520 4092 1464 R 0.7 0.2 0:00.66 htop 1 root 20 0 129484 3716 2412 S 0.0 0.2 0:03.03 systemd (continued)
With the bars at the top, it’s easy to know how your system is doing with just a glance, along with customizable detailed info available just below them.
By using any of these tools, you can easily find the exact information that you need regarding your services and processes.
PS. If you liked this post on how to see which services are running in Linux, please share it with your friends through social media by using the share shortcuts, or simply leave a comment below. Thanks.