- Check Memory Usage of Process with Linux Top Command
- Top sort by memory
- Using shortcut keys
- Using a single command
- Conclusion
- Find Top 15 Processes by Memory Usage with ‘top’ in Batch Mode
- Redirect or Save ‘top’ Output to File in Linux
- If You Appreciate What We Do Here On TecMint, You Should Consider:
- How to use top sort by cpu and by memory in linux
- top sort by CPU in linux
- top sort by memory in linux
- top sort by pid in linux
- top command supports sorted fields
- Descriptions of fields
- TOP command memory usage
- 3 Answers 3
- How does the top command sort by memory in linux/unix
- top option -o
- top interactive mode
Check Memory Usage of Process with Linux Top Command
Generally, we look at the memory usage using the free command that provides us the total physical memory and used memory out of total memory. But top command is more useful to check memory usage in Linux. The free command display only physical memory usage but top display virtual memory usages by each process. It displays how much memory % a process is consuming separately for each running process.
Top command displays a listing of the most CPU utilization tasks and also can sort the tasks by CPU usage, memory usage and runtime.
Top sort by memory
Open shell to run top command, if we run top it will display only command name of the running process, to see full command we use -c option with top.
Then press m it will sort output with an order of highest memory usage at top as below:
Also you can run top command as following
Then press SHIFT + m from the keyboard to sort by memory usage.
Using shortcut keys
Modern Linux distro supports interactive menu for top to select memory usage.
Follow the below steps:
- press Shift+f to enter the interactive menu.
- press the up or down arrow until the %MEM choice is highlighted.
- press s to select %MEM choice.
- press enter to save your selection and exit ( q )the interactive menu.
Below screenshot shows the interactive menu Shift+f :
In older version of Linux it would be bit different as follows:
Run top command and press shift + f then the output will as displayed as shown below:
Now press the letter corresponding to %MEM ie ‘n’ and then press ‘ENTER’ key.
Using a single command
You can run the following single top command from the terminal to display memory usage:
Conclusion
In this tutorial we used top command to display active process usage ordered by memory usage. Linux also have ps and pmap commands to check memory usage.
If you have any questions or feedback, feel free to leave a comment.
Источник
Find Top 15 Processes by Memory Usage with ‘top’ in Batch Mode
Similarly to the previous tip about find out top processes by RAM and CPU usage, you can also use top command to view the same information. Perhaps there’s an extra advantage of this approach when compared to the previous one: the “header” of top provides extra information about the current status and usage of the system: the uptime, load average, and total number of processes, to name a few examples.
Find Processes By Memory Usage with top
To display the top 15 processes sorted by memory use in descending order, do:
As opposed to the previous tip, here you have to use +%MEM (note the plus sign) to sort the output in descending order:
List Top 15 Processes By Memory Usage
From the command above, the option:
- -b : runs top in batch mode
- -o : used to specify fields for sorting processes
- head utility displays the first few lines of a file and
- the -n option is used to specify the number of lines to be displayed.
Note that head utility, by default displays the first ten lines of a file, that is when you do not specify the number of lines to be displayed. Therefore, in the example above, we displayed the first 22 lines of top command output in batch mode.
Redirect or Save ‘top’ Output to File in Linux
Additionally, using top in batch mode allows you to redirect the output to a file for later inspection:
As we have seen, the top utility offers us more dynamic information while listing processes on a Linux system, therefore, this approach has an extra advantage compared to using ps utility which we covered in tip one.
But most importantly, you must always run top in batch mode to redirect its output to a file or another process. Additionally, if you have any tips regarding use of top, you can also share them with us via the feedback form below.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Источник
How to use top sort by cpu and by memory in linux
Linux top command plays a vital role in daily monitoring of server status.
This linux tutorial mainly shares with you how to sort the linux system CPU usage or memory usage when using the linux top command.
top sort by CPU in linux
A leading ‘+’ will force sorting high to low, whereas a ‘-” will ensure a low to high ordering.
top sort by memory in linux
top sort by pid in linux
top command supports sorted fields
Descriptions of fields
- PID: Shows task’s unique process id.
- USER: User name of owner of task.
- PR: Stands for priority of the task.
- NI: Represents a Nice Value of task. A Negative nice value implies higher priority, and positive Nice value means lower priority.
- VIRT: Total virtual memory used by the task.
- RES: Resident Memory Size (KiB).
- SHR: Represents the Shared Memory size (kb) used by a task.
- S : Process Status. The status of the task which can be one of:
- D = uninterruptible sleep
- I = idle
- R = running
- S = sleeping
- T = stopped by job control signal
- t = stopped by debugger during trace
- Z = zombie
- %CPU: Represents the CPU usage.
- %MEM: Shows the Memory usage of task.
- TIME+: CPU Time, the same as ‘TIME’, but reflecting more granularity through hundredths of a second.
- COMMAND: Command Name or Command Line.
Best linux commands articles:
Источник
TOP command memory usage
Under SuSE, (Mem: 31908592k total, 31421504k used,) how do i know which process or program using my memory?
3 Answers 3
The standard (command-line) program for checking cpu/memory usage for processes is top there is also a slightly more feature-full htop however on a lot of systems its bound to top anyway (same way bash is almost always bound to sh on most modern linux systems). There are also various GUI wrappers for top/htop available
After opening top, clicking M will sort by memory usage.
EDIT — 4-12 For clarity I decided to expand on the sorting. Here is a typical top window when run from the terminal shell, this is already sorted by %MEM
The column that interests you most is %MEM which will give you the share of total available memory used by that process. VIRT gives the virtual memory footprint of the process, of which only RES amount is currently in physical memory (the rest is swapped out, and not currently shown on the table)
In order to sort by a column you hit F (shift-F) and the screen will change to the following
as you can see, hitting n will select sort by memory percentage (hit enter to return back to the table view). (There is a legacy shortcut Shift-m that will toggle sort by memory when hit on the table view) You can use and > in the table view (shift — , and shift-.) to cycle the column that is sorted.
At the table view, hitting lowercase m will toggle the memory summary view.
Note: I played around with sorting columns so the columns are shuffled from the first image.
Like a lot of unix/linux command line utilities there are many little tricks and things and hidden features — top is a very powerful tool. For instance, you can show multiple tables at the same time (say the top 5 instead of top 20 but for 4-5 different parameters)- how? I don’t know, but I accidentally got to that when taking the screenshots. A full chapter of a good book on *nix can be devoted to top , so the summary above is just a small primer to get what you need to know about your processes.
Источник
How does the top command sort by memory in linux/unix
Linux top sort by memory can help us find out which processes use more memory.
In linux/unix, there are two ways to sort by memory using the top command:
- topoption -o
- top interactive mode
Let’s take a look at how to use the top command to sort processes by memory usage.
top option -o
The linux top command can use the -o option to sort the keys that support sorting fields in ascending or descending order.
Memory supports sorting related keys:
- mem Physical memory footprint of the process.
- rprvt Resident private address space size.
- purg Purgeable memory size.
- vsize Total memory size.
- vprvt Private address space size.
- kprvt Private kernel memory size.
- kshrd Shared kernel memory size.
Top sort syntax:
Top example 1
In the following top example, we will use the top command to sort the physical memory usage of the process in descending order.
When using the top -o option to sort key, you can use the symbol before the key: ” + “ or ” – “ :
- + Indicates descending order;
- – Indicates ascending order;
top -o defaults to ascending order.
Top example 2
top Sort by ascending memory usage:
The top -o option can not only sort memory, but also sort other supported sort fields (support sort key, see man top).
Use the top -o option to sort the CPU usage as follows:
top interactive mode
In the top interactive mode, you need to execute the top command directly on the terminal, and then enter the interactive command on the top monitoring page.
Interactive mode, top sort command:
okey Order the process display by sorting on key in descending order.
Examples
1. Open the terminal and execute the top command.
2. Enter the top interactive sorting command: omem
a. When you enter the letter ” o “, you will find that the red box shows the default sort order of the current top command: cpu descending order
b. Continue typing ” mem “ and press Enter. You will find that the top monitoring page has been sorted in descending order of memory usage.
c. When you enter the letter ” o “ again, the monitoring page will display the sorting method used by the current top command.
-mem: Sort by memory usage in descending order
This interactive mode is also sorted by other keys.
Linux top two ways to sort by memory: top -o option and top interactive mode, have you learned?
Источник