How do I sort by memory usage (or CPU usage sort) After the top command is started under Linux?

Source: Internet
Author: User

There is no way to do this directly in the parameters of the top command.

Man top wrote

NAME
Top-display Linux Tasks

Synopsis
TOP-HV | -bchiss-d delay-n iterations-p pid [, PID ...]

The traditional switches '-' and whitespace are optional.

-b:batch mode operation
-c:command Line/program Name Toggle
-d:delay time interval as:-D ss.tt (seconds.tenths)
-h:help
-h:threads Toggle
-i:idle Processes Toggle
-n:number of iterations limit as:-N number
-u:monitor by user as:-U Somebody
-u:monitor by user as:-U Somebody
-p:monitor PIDs as:-pn1-pn2 ... or-pn1, N2 [,...]
-s:secure mode operation
-s:cumulative Time Mode Toggle
-v:version
-m:detect Memory Units

However, you can use interactive commands when the text is displayed in full screen, such as uppercase M to make the process appear sorted by memory usage, and by CPU using the uppercase p.

You can save the current settings in the configuration file by using the upper case w, which is generally ~/.TOPRC, so that the next launch of the top command is displayed in a set order.

Man top wrote

W:write_the_configuration_file
This would save all of your options and toggles plus the current
Display mode and delay time. By issuing this command just
Before quitting top, you'll be being able restart later in exactly
That's same state.

1:toggle_single/separate_cpu_states-On/off
This command affects the "T ' command ' s CPU states portion is
Shown. Although this toggle exists primarily to serve mas-
Sively-parallel SMP machines, it isn't restricted to solely SMP
Environments.

Sorting of Task window
For compatibility, this top supports most of the former top sort
Keys. Since This was primarily a service to former top users, these
Commands does not appear on any to help screen.
Command sorted field supported
A start Time (non-display) No
M%MEM Yes
N PID Yes
P%cpu Yes
T time+ Yes

Below is a sample of a ~/.TOPRC file. This file is a little complicated, not carefully read.

Text Code

  1. Rcfile for "Top with Windows" # shameless Braggin '

  2. Id:a, mode_altscr=0, mode_irixps=1, delay_time=3.000, curwin=0

  3. Def Fieldscur=aehioqtwknmbcdfgjplrsuvyzx

  4. winflags=62777, sortindx=, maxtasks=0

  5. summclr=1, msgsclr=1, headclr=3, taskclr=1

  6. Job FIELDSCUR=ABCEFGJLRSTUVYZMKNHIWOPQDX

  7. winflags=62777, sortindx=0, maxtasks=0

  8. summclr=6, msgsclr=6, headclr=7, taskclr=6

  9. Mem Fieldscur=anopqrstuvbcdefgjlmyzwhikx

  10. winflags=62777, sortindx=, maxtasks=0

  11. Summclr=5, msgsclr=5, headclr=4, taskclr=5

  12. USR FIELDSCUR=ABDECGFHIJLOPQRSTUVYZMKNWX

  13. winflags=62777, sortindx=4, maxtasks=0

  14. Summclr=3, msgsclr=3, headclr=2, taskclr=3


How do I sort by memory usage (or CPU usage sort) After the top command is started under Linux?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.