How to View Current Processes on a Cómo Monitorizar el Espacio Libre en Disco de tu VDS Fácilmente con un Script" class="internal-post-link">Cómo Monitorizar los Procesos Activos en tu VPS Linux Ubuntu en 2025: Guía Actualizada" class="internal-post-link">Linux Ubuntu VPS?
Process management is a critical task for any VPS (Virtual Private Server) administrator on Ubuntu. Knowing how to view current processes allows you to monitor resource consumption, identify problematic applications, and ensure stable server operation. In this article, we will thoroughly examine various ways to view processes on an Ubuntu VPS, provide practical examples of using the command line and GUI tools, and share helpful tips for interpreting the obtained data.
We will explore the ps, top, htop commands, and other tools that allow you to obtain comprehensive information about running processes. You will learn how to filter processes by user, PID (Process ID), and other criteria, and also learn how to analyze resource usage (CPU, RAM) by each process. This information will help you optimize the performance of your VPS and quickly respond to any problems.
- ps command: basic overview of processes
- Interactive monitoring with top and htop
- Filtering processes: search by user and PID
- Analyzing resource usage by processes
- Viewing processes managed by Systemd
ps command: basic overview of processes
Theps (process status) command is one of the most basic and powerful tools for viewing information about processes in Linux. It provides a snapshot of the current processes in the system. There are many options for the ps command that allow you to customize the output of information according to your needs.
The basic ps command without options will only show processes running in the current shell. To get a more complete list of processes, the aux options are usually used.
ps aux
This command will output a list of all processes running in the system, with detailed information about each process. Let’s break down the columns of the ps aux command output:
- USER: The name of the user who owns the process.
- PID: The process identifier (Process ID).
- %CPU: The percentage of CPU usage by the process.
- %MEM: The percentage of RAM usage by the process.
- VSZ: The virtual size of the process (in kilobytes).
- RSS: The real size of the process in RAM (in kilobytes).
- TTY: The terminal to which the process is attached (if any).
?means that the process is not attached to a terminal. - STAT: The status of the process (for example,
S– sleeping,R– running,Z– zombie). - START: The time the process started.
- TIME: The total CPU usage time by the process.
- COMMAND: The command that started the process.
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 16704 4192 ? Ss Dec01 0:03 /sbin/init
root 2 0.0 0.0 0 0 ? S Dec01 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? I< Dec01 0:00 [rcu_gp]
root 4 0.0 0.0 0 0 ? I< Dec01 0:00 [rcu_par_gp]
root 6 0.0 0.0 0 0 ? I< Dec01 0:00 [kworker/0:0H-kblockd]
...
Another useful option of the ps command is -f (full format), which provides more information about the process, including the parent PID (PPID). This can be useful for tracking the process hierarchy.
ps -f
By combining options, you can get even more detailed information. For example, ps auxf will output a list of all processes with full information and display the process hierarchy as a tree.
ps auxf
Another common use case is ps -ef, which also displays all processes, but uses a different output format, more familiar to System V systems.
ps -ef
Expert tip: To search for a specific process by name, you can use the ps command in combination with grep. For example, to find all processes containing "nginx" in their name, you can use the following command:
ps aux | grep nginx
This will quickly find processes related to a specific application.
Interactive monitoring with top and htop
Thetop and htop commands are interactive tools that allow you to monitor system and process resource usage in real time. They provide dynamic information about CPU load, memory usage, uptime, and other important parameters.
top is a standard utility that is usually pre-installed on most Linux distributions. To run top, simply enter the command in the terminal:
top
After starting top, a dynamic list of processes will be displayed, sorted by default by CPU usage percentage. The top of the screen displays summary information about the system, including CPU load, memory usage (RAM and swap), and the number of running processes.
Inside top, you can use various commands to control the display of information. For example:
q: Exittop.h: Display help.k: Terminate a process (requires entering the PID).M: Sort processes by memory usage.P: Sort processes by CPU usage.1: Display information about each CPU (if you have a multi-core processor).
htop is a more advanced version of top with an improved interface and additional features. It also displays information about processes in real time, but has a more user-friendly interface with color highlighting and the ability to navigate using the cursor control keys.
htop is usually not pre-installed, so it must be installed separately. On Ubuntu, this can be done with the command:
sudo apt update
sudo apt install htop
After installation, run htop with the command:
htop
htop makes it easy to kill processes, change their priority (nice value), and filter the list of processes. It also displays CPU load information by core, allowing for a more detailed analysis of system performance.
Comparison of top and htop:
| Function | top | htop |
|---|---|---|
| Interface | Text-based, less convenient | Interactive, with color highlighting |
| Process management | Limited capabilities | Advanced capabilities (killing, changing priority) |
| CPU monitoring | Total CPU load | CPU load per core |
| Installation | Usually pre-installed | Requires installation |
htop: Suppose you notice that your VPS is running slowly. Run htop and see which processes are consuming the most CPU and memory. If you find a process that is consuming resources inappropriately, you can kill it directly from htop by selecting the process and pressing the F9 key.
Expert tip: htop can be configured using the configuration file ~/.config/htop/htoprc. You can change colors, add or remove columns, and customize other display settings.
Filtering processes: search by user and PID
Often there is a need to filter the list of processes to find a specific process or group of processes belonging to a specific user. For this, you can use various tools and options of theps command.
Filtering by user:
One way to filter processes by user is to use the ps command in combination with the grep command. For example, to find all processes belonging to the user "john", you can use the following command:
ps aux | grep john
This command will output a list of all processes in which the user name matches "john". However, this method may give false positives if the user name occurs in the process command.
A more accurate way is to use the -u option of the ps command. This option allows you to specify the user name whose processes you want to display.
ps -u john
This command will output a list of all processes belonging to the user "john".
Filtering by PID:
Sometimes it is necessary to get information about a specific process by its PID (Process ID). For this, you can also use the ps command.
ps -p PID
Replace PID with the real process identifier. For example, to get information about the process with PID 1234, use:
ps -p 1234
This command will output information about the process with the specified PID.
Another way to get the PID of a process by its name is to use the pidof command. For example, to get the PID of the "nginx" process, use:
pidof nginx
This command will output the PID of the "nginx" process. If multiple processes with that name are running, it will output all PIDs separated by a space.
You can also use the pgrep command to search for processes by name or other criteria. pgrep returns the PIDs of processes that match the specified pattern.
pgrep nginx
This command will also output the PID of the "nginx" process. pgrep has more options for filtering processes, for example, you can filter processes by user name:
pgrep -u john nginx
This command will output the PID of the "nginx" process belonging to the user "john".
Example: Suppose you want to stop the Apache process belonging to the user "www-data". First, find the PID of the process using pgrep:
pgrep -u www-data apache2
Then use the kill command to terminate the process:
sudo kill PID
Replace PID with the PID obtained from pgrep.
Expert tip: To automatically terminate all processes belonging to a specific user, you can use the pkill command:
sudo pkill -u john
This command will terminate all processes belonging to the user "john". Be careful when using this command, as it can lead to data loss if the processes have not been terminated correctly.
Analyzing resource usage by processes
Analyzing resource usage by processes is an important step in optimizing VPS performance. It is necessary to understand which processes consume the most CPU and memory in order to identify potential problems and take the necessary measures. As we have already discussed, thetop and htop commands provide information about resource usage in real time. However, you can also use the ps command to get more detailed information.
CPU usage:
To see processes sorted by CPU usage, you can use the ps command with the -o option to specify the columns to display, and the sort command to sort the results.
ps -eo pid,pcpu,comm | sort -k2 -r | head -n 10
This command will output 10 processes consuming the most CPU, sorted in descending order. Let's break down the command:
ps -eo pid,pcpu,comm: Outputs the PID, CPU usage percentage (%CPU) and command name (comm) for all processes.sort -k2 -r: Sorts the results by the second column (CPU) in reverse order (from largest to smallest).head -n 10: Outputs the first 10 lines of the results.
ps -eo pid,pmem,comm | sort -k2 -r | head -n 10
This command will output 10 processes consuming the most memory, sorted in descending order. Here pmem means the percentage of memory usage (%MEM).
To display the actual amount of memory used by the process (RSS - Resident Set Size), you can use the following command:
ps -eo pid,rss,comm | sort -k2 -r | head -n 10
This command will output 10 processes using the most real memory, sorted in descending order. The RSS value is displayed in kilobytes.
Analyzing resource consumption by a specific process:
If you know the PID of the process, you can use the ps command with the -p option to get information about its resource usage:
ps -p PID -o pid,pcpu,pmem,rss,vsz,comm
Replace PID with the real process identifier. This command will output the PID, CPU usage percentage, memory usage percentage, real size (RSS), virtual size (VSZ) and command name (comm) for the specified process.
Example: Suppose you notice that a process with PID 4567 is consuming a lot of resources. Run the following command:
ps -p 4567 -o pid,pcpu,pmem,rss,vsz,comm
The command output will show you how much CPU and memory this process is using, which will help you determine whether this is normal behavior or indicates a problem.
Expert tip: For long-term monitoring of resource usage, you can use tools such as sar (System Activity Reporter) or collectd. They allow you to collect statistics about resource usage by the system and processes over time, which is useful for identifying trends and bottlenecks.
Viewing processes managed by Systemd
Systemd is a system and service manager that is used in most modern Linux distributions, including Ubuntu. Systemd manages most system services and applications, so it is important to be able to view processes managed by Systemd. Systemd uses the concept of "units" to represent services, sockets, devices, and other system components. Each unit has a corresponding configuration file that defines its behavior. To view a list of all units managed by Systemd, you can use thesystemctl list-units command:
systemctl list-units
This command will output a list of all units, their current state (loaded, active, sub) and a description. The "active" state means that the unit is running and working.
To filter the list and display only running units, you can use the --state=active option:
systemctl list-units --state=active
To view information about a specific unit, for example, the "nginx.service" service, you can use the systemctl status command:
systemctl status nginx.service
This command will output detailed information about the nginx service, including its status, the PID of the main process, resource usage, and recent logs. If the service is not running, the command will display a corresponding message.
To get a list of processes associated with a specific unit, you can use the systemd-cgls (Control Group List) command:
systemd-cgls
This command will output a list of all Systemd control groups (cgroups) and their associated processes. To filter by a specific unit, you can specify its name:
systemd-cgls nginx.service
This command will output a list of processes associated with the nginx service.
Another way to get information about processes managed by Systemd is to use the ps command in combination with filtering by cgroup. Each Systemd unit has its own cgroup, and you can use this information to filter processes.
To find out the cgroup for the nginx service, you can use the command:
systemctl show nginx.service | grep ControlGroup
This command will output a string containing the cgroup for the nginx service. For example, the output might be:
ControlGroup=/system.slice/nginx.service
You can then use this information to filter processes using the ps and grep commands:
ps axjf | grep '/system.slice/nginx.service'
This command will output a list of processes associated with the nginx service.
Example: Suppose you want to restart the Apache service and check that all processes associated with it have been restarted correctly. First, restart the service:
sudo systemctl restart apache2.service
Then check the service status:
systemctl status apache2.service
And finally, make sure that all processes have been restarted correctly by viewing the list of processes associated with the service:
systemd-cgls apache2.service
Expert tip: Systemd also provides the ability to monitor the resources used by units using the systemd-cgtop command. This command displays a list of units sorted by CPU and memory usage, allowing you to quickly identify units that are consuming the most resources. systemd-cgtop may not be installed by default and may require the installation of a separate package.