The Linux top command is not only used for looking at processor activities in real-time but also helpful when you need corrective action for your Linux operating systems.
The best and the simplest way to monitor running activities and system resources is by using the top command. System Administrators use it as an important toolbox utility as most Linux distros have the installation by default. The interactive command allows you to use browse processes or issue a kill command Linux to terminate a particular process.
The guide illustrates different approaches the top command can be effective in checking your system as an administrator. All you need to do is to run the terminal through the dashboard or use the CTRL+ALT+T combination.
The Interface
Running the command “top” will reveal the interface with the upper section showing statistics on running processes. The bottom part indicates the running processes. Use the arrow keys, page up, or page down keys to scroll up or down the page.
Quitting the command means issuing the CTRL+C shortcut or hit the q.
View Help options
The top command help page has a list of options that can help customize output and functions. View the help page while the command is running by hitting the h key.
Setting Intervals to Refresh the Screen
The default refresh time for the top command is three seconds. To change the timing hit the d key when the command is active, and then enter the new interval in seconds and it takes effect immediately.
Display Processes of a Particular User
Use the following command structure for the user tecmint.
$ top –u jay
Use Top Command to Kill Running Process
The kill command Linux is a powerful feature that stops a running process. You can issue the kill command when the process is non-responsive and you want to end it. Use the k key when the command is active, you will be prompted with a question on the PID (process ID). Once you enter the PID seen from a list of processes, hit the enter key.
Changing Process Priority
Using renice will change the priority given to a process. When the top command is running use the r key followed by the process of PID.
Exit the top Command after a Specific Number of Refreshing
To manage the time it takes the top command to execute, use the following syntax
$ top –n [no-of-refreshes]
The example given below will refresh the top command five times and automatically exit after the fifth refresh.
$ top –n 3
Saving the Results in a Text File
It is possible to save the top command output to a text file. Use the following command
$ top –n [no-of-intervals] –b > “sample filename.txt”
In the example that follows, the output will be saved to a file with the name tecmint.txt
$ top –n 1 -b > james.txt
Those are some of the nifty and useful uses of the Top command in Linux. We hope you found this insightful. Thank you for your time.