Managing Processes

Instructions

Q&A (0)

Notes (0)

Resources (0)

Saving Progress...

Resources

There are no resources for this lesson.

Notes can be saved and accessed anywhere in the course. They also double as bookmarks so you can quickly review important lesson material.

Create note

In this lesson, you will learn how to manage processes on a Linux server. You will learn tools like ps, top, and kill. We will use the nginx package as our example. To get started, go ahead and install the nginx package with the command below:

sudo apt install nginx

Understanding NGINX as a Process

When NGINX is running on your Ubuntu Server, it operates as a process. This process can be viewed, managed, and terminated if necessary, using Linux commands. Knowing how to view and kill processes is an extremely important skill that I want to make sure you understand - so we will cover that in this lesson.

The top utility

The top command in Linux is an incredibly useful tool for monitoring system performance and managing processes. It provides a real-time, dynamic view of your system's resource usage, including CPU, memory, and process information. In this lesson, we'll focus on some essential skills you should have when using top, with a special emphasis on searching for process names.

Opening top

To start top, simply type the following command in your terminal:

top

Navigating the top Interface

Once top is running, you'll see a display showing a list of the system's currently running processes, along with information about system resources. The top portion shows overall system statistics, while the bottom portion lists individual processes.

Sorting Processes

By default, top sorts processes based on CPU usage, but you can sort by other criteria (you must use shift to capitalize each of the letters below):

Searching for Process Names

One key skill in top is searching for specific processes by name. This is particularly useful when you're monitoring a specific application or service. To search for a process:

If there are multiple instances of the process, you can press L and enter the name again to cycle through them.

Killing Processes from top

If you find a process that needs to be terminated, you can do so directly from top:

Forcefully kill all the nginx processes, then exit top using the instructions below.

Exiting top

To exit top, simply press q. This will return you to the command line. Check the status of nginx to make sure it was stopped:

paulh@ubuntu-server:~$ systemctl status nginx
× nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; disabled; vendor preset: enabled)
     Active: failed (Result: signal) since Tue 2023-12-05 20:37:57 UTC; 9s ago
       Docs: man:nginx(8)
    Process: 74006 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0>
    Process: 74007 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 74008 (code=killed, signal=KILL)
        CPU: 20ms

Then you can start nginx back up with the command below:

sudo systemctl status nginx

Viewing Processes with ps

Use the ps command with options aux piped to the grep command to filter for all NGINX processes:

ps aux | grep nginx

This should return an output similar to the following:

I manually added the first line in the output below so you can see each column name, but you will be missing the first row due to the grep command filtering it out

USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       74008  0.0  0.0  55220  1680 ?        Ss   20:30   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data   74009  0.0  0.0  55852  5608 ?        S    20:30   0:00 nginx: worker process
www-data   74010  0.0  0.0  55852  5608 ?        S    20:30   0:00 nginx: worker process
www-data   74011  0.0  0.0  55852  5608 ?        S    20:30   0:00 nginx: worker process
www-data   74012  0.0  0.0  55852  5608 ?        S    20:30   0:00 nginx: worker process
paulh      74027  0.0  0.0   6476  2220 pts/0    S+   20:30   0:00 grep --color=auto nginx

Killing processes with kill

If you need to stop the NGINX process, perhaps due to unresponsiveness or for maintenance purposes, you can do so using the kill command.

Server Academy Members Only

Want to access this lesson? Just sign up for a free Server Academy account and you'll be on your way. Already have an account? Click the Sign Up Free button to get started..

0 0 votes
Lesson Rating
Subscribe
Notify of
profile avatar
0 Comments
Inline Feedbacks
View all comments