In your server, there are lots of ways you could view a system resource usage, as well as the ability to kill a misbehaving or resource hog processes, for example, you can use the kill command to gracefully kill a process, learn more about Dealing With Misbehaving Processes in Your Server.
What if I tell you that there is a better way to go about it, which is where the htop utility comes in...
htop is an interactive process viewer that allows you to scroll vertically, and horizontally, this way, you can see the processes running on the system, along with commands running the process, the good thing about this utility is that it features mouse support, and on top of that, you can kill processes without the need of figuring out their PIDS.
If you are running Ubuntu 18 and above, then you most likely would have htop installed by default, if you don't already have htop installed, you can install it with apt:
sudo apt install htop
To get started with htop, simply run htop at your shell prompt, but I love to run it as root, this would give me an option to kill processes:
sudo htop
At the top left section of the htop display is the progress bar for each of your CPU cores (I have one core in the screenshot above), plus a usage bar for both memory and swap.
The CPU usage bar displays the used percentage of the CPU, the memory bar shows the used/total size of the memory, while the swap bar shows the used/total size of the swap.
At the top right section of the htop display are the number of Tasks you have running, Load average, and your server uptime.
The lower section of the htop display will show you a list of processes running on your server, with a column showing you the user running, Its PID, memory, and CPU being consumed by each process, and the command being run.
To scroll the process list, you can use your arrow keys to navigate up and down through the list, and here is what I love about htop, you can use your mouse to sort the list of processes, e.g if you click on MEM% or CPU%, the process list will be sorted by memory or CPU usage respectively.
Watch the below video for an illustration:
https://youtu.be/Io_sZyKmFbI
At the bottommost part are short-cut keys you can utilize for even more advance stuff, I have highlighted what the major functions are used for below, and also include a video for illustration:
F2 or Capital Letter "S" | This takes you to the setup screen where you can configure the meters displayed at the top of the screen, set various display options, choose among color schemes, and select which columns are displayed, in which order. |
F3 or / | It Incrementally searches the command lines of all the displayed processes. The currently selected (highlighted) command will update as you type. While in search mode, pressing F3 will cycle through matching occurrences. |
F4 \ | This is similar to the search function, but in this case, it only shows processes whose names match with what you typed |
F5 or small letter "t" | This shows the process in a tree view, the way it works is organizing the processes by parenthood, and layout the relations between them as a tree. This is useful in a situation where you are stopping a process only to have it immediately respawn, you would need to know what the parent of that process is in order to stop it from resurrecting itself. |
F6 | This is the sorted view, this is the same as clicking on MEM%, CPU%, etc |
F9, or small letter "k" | The kill process sends a signal which is selected in a menu, for example, Signal 15(SIGTERM) kills the process gracefully, and the signal 9(SIGKILL) force stop a process ungracefully. |
F10 or small letter "q" | Quite htop |
Watch the below video for an illustration:
https://youtu.be/vR6nSANZyX4
htop can really be useful for monitoring system processes, and their usages!