Linux top sorted by memory

How to find which processes are taking all the memory?

Under Linux, simply press M to sort by physical memory usage (RES column). Under *BSD, run top -o res or top -o size . But htop is a lot nicer and doesn’t even consume more memory than top (however it’s not part of the basic toolset so you might not have it installed).

@Steven How can we group process with same parent? Basically firefox shows up in multiple times may be as it spawns multiple child processes. Is it possible to get combined memory usage?

If you have it installed I like htop once launching it you can press f6 , down arrow (to MEM% ), enter to sort by memory.

In Solaris the command you would need is:

This will list all processes in order of descending process image size. Note that the latter is based on memory committed to the process by the OS, not its resident physical memory usage.

There are supposedly versions of «top» available for Solaris, but these are not part of the standard installation.

Once top starts, press F to switch to the sort field screen. Choose one of the fields listed by pressing the key listed on the left; you probably want N for MEM%

If you want MEM%, pressing ‘M’ does the same stated above. ‘c’ adds command line parameters to the process list, may be informative for your problem.

This command will identify the top memory consuming processes:

ps -A --sort -rss -o pid,pmem:40,cmd:500 | head -n 6 | tr -s " " ";z" 

Doesn’t work on Solaris 9: ps: illegal option — — ps: ort is an invalid non-numeric argument for -s option ps: illegal option — r ps: s is an invalid non-numeric argument for -s option ps: unknown output format: -o pmem:40 ps: unknown output format: -o cmd:500

One nice alternative to top is htop . Check it, it is much more user friendly than regular top.

Globally: It’s always recommended to use a log analyser tool for logging history logs such as Splunk, ELK etc. So that using query language you can easily get the PIDs and its usage by CPU & memory.

AT SERVER/OS LEVEL: From inside top you can try the following:

 Press SHIFT+M ---> This will give you a process which takes more memory in descending order. 
$ ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head -10 

This will give the top 10 processes by memory usage. Also you can use vmstat utility to find the RAM usage at same time not for history.

Источник

How to Make Top Command Sort by Memory Usage

Top is a Linux process and resource usage monitoring utility. It allows users to view real-time information about the running processes and threads managed by the system’s kernel. Because of its interactivity, top enables users to perform tasks, such as filtering for specific processes, filter processes by users, PID, and kill processes.

Читайте также:  Linux c hex to int

This guide will walk you through the basics of using the ps command to locate specific information about the system.

Basic Top Utility Usage

To launch the top utility, use the top command in the terminal. Using this command will spawn an interactive session showing system resource usage and running processes:

The upper part shows the resource usage. This output is similar to that of uptime and the free command in Linux.

To turn these values off, press “m” to hide the memory usage information and “l” to hide the uptime information.

To scroll through the running processes, use the up and down arrow key. To quit, press “Q”.

Top Output

The lower part of top command contains information about running processes. Let us focus on this.

The output uses a column-based organization, with an identifier on each:

  • PID: This column shows the unique ID of each process.
  • PR: This column shows the priority of the task.
  • NI: This column shows the nice value of the process. A positive value indicates low priority, while a negative value indicates high priority.
  • VIRT: This column represents the total virtual memory used by the process.
  • RES: This column shows the total actual memory used by the process.
  • SHR: This column shows the total amount of shared memory used by the process.
  • S: This column shows the process state in a single letter.
  • %CPU: This column shows percentage CPU usage per process.
  • %MEM: This column shows percentage Memory usage.
  • TIME+: This column shows CPU time used by the process calculated to hundredths of a second.
  • COMMAND: This column shows the process name.

How to Make Top Filter Processes by Memory Usage

You can also filter processes by memory usage in top. To do this, press SHIFT + m as shown:

Top will filter the processes by memory usage in descending order. Doing this can help identify the process using the most memory, giving you a chance to take action.

To filter by actual memory usage, use the command:

Similarly, the command will filter the memory usage in descending order.

You can also interactively choose the filter parameter. To do this, press SHIFT + F and select MEM as:

How to Filter Process by User

To show processes from a specific user, use the command:

For example, to show processes from the ubuntu user; enter the command:

How to Show the Parent and Child Processes

To show the parent and child processes while top is running, press V. This will give you an output similar to the one shown below:

How to Kill All Processes

To kill a process in top, press k and enter the PID of the process.

Press enter to execute the kill command. This will terminate the process with the specified PID.

Conclusion

Top is a handy utility that makes it possible to understand and manage the Linux System processes. Besides what we have discussed in this tutorial, top has tons of other functionalities.

To understand how you can customize and use top to its full potential, consider the manuals.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list

Источник

How to display `top` results sorted by memory usage in real time?

How can I display the top results in my terminal in real time so that the list is sorted by memory usage?

Читайте также:  Как подключится удаленно на linux

On Linux, > and < move the sort column right and left. Since the %MEM column is just right of the %CPU column, which is also the default sort column, it takes only one keystroke to switch between the two. I know, your question has the macintosh tag, that's why I'm writing this answer as a comment.

If using htop , in addition to shift + M , you will likely want to turn off the display of threads and just show the main process memory consumption with shift + H . See unix.stackexchange.com/a/10403/27902.

9 Answers 9

Use the top command in Linux/Unix:

  • press shift + m after running the top command
  • or you can interactively choose which column to sort on
    • 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
    • press q to exit the interactive menu

    Or specify the sort order on the command line

    # on OS-X top -o MEM # other distros top -o %MEM 

    References

    @GabrielHautclocq It must depend upon your distribution of Linux, and the package bundled with it. Debian 7 uses procps-ng and there is no -o option at all in that version. SHIFT-M works for me once top is launched.

    The command line option -o (o standing for «Override-sort-field») also works on my Xubuntu machine and according to the Mac man page of top it should work on a Macintosh too. If I want to short by memory usage I usually use

    which sorts by the column %MEM . But I can use VIRT , RES or SHR too. On a Macintosh I would probably use mem or vsize .

    I don’t know why or how but this is pretty much different between Unix systems and even between Linux distributions. For example -o isn’t even available on my Raspberry running Wheezy. It may be worth give it a try though.

    Источник

    How to Sort Top Command Based on Memory Usage

    Top command shows the most CPU consuming processes first. Learn how to sort top on memory usage instead.

    As a Linux user, you cannot avoid the top command. This simple command gives an overview of the all running system process. It refreshes the stats every three seconds and gives you the feeling of continuously monitoring the processes.

    By default, the output of the top command is sorted on the CPU consumption. This means that you see the processes that consume the most CPU is on the top of the command.

    But what if you want to see the processes that consume the most of the RAM? You can sort top command based on memory usage instead of CPU consumption.

    It’s quite simple. Here’s how to do that.

    Sort top command to show memory usage by processes

    Step 1: Run the top command as usual.

    Step 2: Press Shift+M to sort the top command output by memory. That’s it. It will instantly start showing processes with most memory usage.

    Top command output sorted on memory usage

    But this is not a permanent change. The next time you run the top command, it will be sorted on CPU usage again.

    Sort the top command on memory, virtual memory or any other parameter

    The Shift+M keyboard shortcut is handy for checking memory usage per process. However, if you want to sort top command on some other field like virtual memory, time spent, shared memory etc, you can use the interactive mode of the top command.

    Step 1: Run the top command, of course.

    Step 2: Press Shift+F to enter the interactive mode.

    Step 3: Use the arrow key to choose a different parameter like %MEM, TIME, VIRT etc. When you are at the desired parameter, press S to sort on it.

    Sort top command on memory usage

    You can see the current sort field in the top right corner. Press Esc or Q to quit the interactive mode. Now the top command output will be sorted on your selected field.

    That’s handy, right? Top command is very powerful bit unfortunately, many people do not know how to use it properly and effectively. If you want more details, I highly recommend our article on using top command.

    Any questions or suggestions? Please leave a comment.

    Источник

    How to see top processes sorted by actual memory usage?

    If I understand correctly, the system has only 362 MB of available memory. My question is: How can I find out which process is consuming most of the memory? Just as background info, the system is running 64bit OpenSuse 12 .

    12 Answers 12

    use quick tip using top command in linux/unix

    and then hit Shift + m (i.e. write a capital M ).

    SORTING of task window For compatibility, this top supports most of the former top sort keys. Since this is primarily a service to former top users, these commands do not appear on any help screen. command sorted-field supported A start time (non-display) No M %MEM Yes N PID Yes P %CPU Yes T TIME+ Yes 

    Or alternatively: hit Shift + f , then choose the display to order by memory usage by hitting key n then press Enter . You will see active process ordered by memory usage

    hi codecowboy, perhaps you can look at commandlinefu.com/commands/view/3/… for more detailed memory used in my server i am using third party app like newrelic.com

    First, repeat this mantra for a little while: «unused memory is wasted memory». The Linux kernel keeps around huge amounts of file metadata and files that were requested, until something that looks more important pushes that data out. It’s why you can run:

    find /home -type f -name '*.mp3' find /home -type f -name '*.aac' 

    and have the second find instance run at ridiculous speed.

    Linux only leaves a little bit of memory ‘free’ to handle spikes in memory usage without too much effort.

    Second, you want to find the processes that are eating all your memory; in top use the M command to sort by memory use. Feel free to ignore the VIRT column, that just tells you how much virtual memory has been allocated, not how much memory the process is using. RES reports how much memory is resident, or currently in ram (as opposed to swapped to disk or never actually allocated in the first place, despite being requested).

    But, since RES will count e.g. /lib/libc.so.6 memory once for nearly every process, it isn’t exactly an awesome measure of how much memory a process is using. The SHR column reports how much memory is shared with other processes, but there is no guarantee that another process is actually sharing — it could be sharable, just no one else wants to share.

    The smem tool is designed to help users better gage just how much memory should really be blamed on each individual process. It does some clever work to figure out what is really unique, what is shared, and proportionally tallies the shared memory to the processes sharing it. smem may help you understand where your memory is going better than top will, but top is an excellent first tool.

    Источник

Оцените статью
Adblock
detector