Ivy Consultants Inc.

Consulting Services for Security, Networking, Wi-Fi and Windows Server

In this lesson, you will learn how to manage processes on a Linux server. You will learn tools like pstop, 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):

  • Press M to sort by memory usage.
  • Press P to sort back by CPU usage.
  • Press T to sort by the time the processes have been running.

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:

  1. Press L (capital L). This opens a search prompt at the bottom of the top interface.
  2. Type the name of the process you’re looking for, like nginx.
  3. Press Entertop will then highlight the first process that matches your search query.

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:

  1. Press k. This opens a prompt asking for the PID of the process you want to kill.
  2. Enter the PID of the process. You can find this in the list of processes.
  3. Press Entertop will then ask for a signal to send. If you press Enter again without typing a signal number, it sends SIGTERM (signal 15), which asks the process to terminate gracefully.
  4. To forcefully kill a process (like using kill -9), type 9 and then press Enter.

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

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:

sonnyb@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