Linux top sort by cpu

How to change top’s sorting back to CPU?

A former coworker did something to top that whenever it runs as root the data is sorted by MEM usage instead of the default CPU usage. According to multiple searches, the man page and even the options within the top console itself (O), just pressing k it should be sorted by CPU, but instead when I hit k it asks me for a pid to kill.

6 Answers 6

To add to the answers already P (upper case P) makes top order by CPU, Then hit W (again upper case W) to save.

Oddly enough this option does not appear to be featured in the man top available on macOS Sierra 10.12.2.

You can change the sort field in the interactive top window with the < and >keys. I’m not sure what operating system you’re running but at least on my GNU top, k is supposed to kill, not reset.

Presumably, your friend changed the sort field and hit Shift + W to save to ~/.toprc . Just use the keys I mentioned to choose the sort field you want and then, when it’s set up as you like it, hit Shift + W again and it should save that state and open that way next time.

Note that you can press z to turn on color mode and then x to highlight the current sort column. Much easier to see what’s going on as you use < and >to change what you’re sorting by.

Actually, pressing x will highlight the current sort column even in non-color mode. Pressing b will toggle bold to highlight it even more.

Читайте также:  Просмотр файловой системы линукс

On Mac OS X, it appears that there is no command to save the options, and man top says nothing about a .toprc file. So it looks like the best you can do there is

I know it’s not a direct answer to your question, but there’s a wonderful tool called htop which I’d like to recommend. It’s like an advanced version of the original top tool which allows you to sort the output in a much easier way and appearance. For example, if you want to sort by CPU, you simply hit F6 and choose your sorting.

Here’s how htop looks like: htop screenshot

Here’s some of the sorting options available: some htop sorting options

In order to install it on CentOS/RHEL machines you will have to add the EPEL repo and then simply run:

or on Debian machines simply run:

sudo apt-get install htop without adding any repo’s.

I’ve written in the past a nice article about htop, feel free to check it.

Источник

16 Top Command Examples in Linux [Monitor Linux Processes]

In our previous articles, we have covered the basics of ls command and cat command. In this article, we are trying to explore the top command which is one of the most frequently used commands in our daily system administrative jobs.

The top command (table of processes) displays the processor activity of your Linux box and also displays tasks managed by the kernel in real-time. It also shows information about CPU and memory utilization of a list of running processes.

You might also be interested in the following tutorials :

1. List All Running Linux Processes

To list all running Linux Processes, simply type top on the command line to get the information of running tasks, memory, cpu, and swap. Press ‘ q ‘ to quit window.

View Linux Running Processes

2. Sort Linux Processes by PID

To sort all Linux running processes by Process ID, press M and T keys.

List of Linux Processes by PID

3. Sort Linux Processes by Memory and CPU Usage

To sort all Linux running processes by Memory usage, press M and P keys.

Sort Linux Processes by Memory CPU Usagae

4. Sort Linux Processes by Running Time

To sort all Linux running processes by running time, press M and T keys.

Sort Linux Processes by Running Time

5. Display Linux Processes By Specific User

To display all user-specific running processes information, use the -u option will list specific User process details.

# top -u tecmint

List Linux Processes By Specific User

6. Highlight Running Process in Top

Press ‘ z ‘ option will display the running process in color which may help you to identify the running process easily.

Читайте также:  Не включается kali linux

Highlight Linux Process

7. List Absolute Path of Running Linux Processes

Press ‘ c ‘ option in running top command will display the absolute path of the running process.

List Linux Processes by Path

8. Set Refresh Interval for Top Command

By default screen refresh interval is set to 3.0 seconds, the same can be changed by pressing the ‘ d ‘ option in running the top command to set desired interval time.

Set Top Command Refresh Time

9. Kill Running Linux Process Using Top Command

You can kill a process after finding the PID of the process by pressing the ‘ k ‘ option in running the top command without closing the top window as shown below.

Kill Linux Process Using PID

10. Sort Linux Processes by CPU Utilisation

To sort all running processes by CPU utilization, simply press Shift+P key.

Sort Linux Processes by CPU Usage

11. Renice a Linux Process

You can use the ‘ r ‘ option to change the priority of the process also called Renice.

Renice Linux Process

12. Check Linux CPU Cores

To list the load information of your CPU cores, simply press 1 to list the CPU core details.

List Linux CPU Cores

13. Save Top Command Results in File

To save the running top command results output to a file /root/.toprc use the following command.

14. List Linux Idle Processes

Press ‘i’ to get the list of idle/sleeping processes.

List Linux Idle Processes

15. Getting Top Command Help

Press the ‘ h ‘ option to obtain the top command help.

Linux Top Command Help

16. Exit Top Command After Specific Repetition

The output of the top command keeps refreshing until you press ‘ q ‘. With the below command, it will automatically exit after 10 repetitions.

There is a number of arguments to know more about the top command, you may refer man page of the top command. Please share it if you find this article useful or share your thoughts using our comment box below.

I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Parted Command in Linux

TLDR Man Pages for Linux Commands

apt-get Command Examples

Ubuntu apt-cache Commands

apt Command Examples

Funny Linux Commands

82 thoughts on “16 Top Command Examples in Linux [Monitor Linux Processes]”

Great article!! Is there any GUI way of visualizing the top command that is output to a file after sort say for CPU utilization? Reply

@Madhav, The -n option specifies the maximum number of iterations and -b enables batch mode operation, which could be useful for sending output from top to a file. Reply

basically I want this output to a file.. for 10 mins.. top – 13:29:09 up 1 day, 20:30, 1 user, load average: 0.65, 0.70, 0.69
Tasks: 1022 total, 1 running, 1020 sleeping, 0 stopped, 1 zombie
%Cpu0 : 13.0 us, 2.7 sy, 0.0 ni, 84.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu1 : 49.3 us, 3.6 sy, 0.0 ni, 45.7 id, 0.3 wa, 0.3 hi, 0.0 si, 0.7 st
%Cpu2 : 2.0 us, 2.0 sy, 0.0 ni, 95.4 id, 0.0 wa, 0.3 hi, 0.3 si, 0.0 st
%Cpu3 : 7.6 us, 2.0 sy, 0.0 ni, 90.4 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu4 : 1.3 us, 2.3 sy, 0.0 ni, 96.0 id, 0.0 wa, 0.0 hi, 0.3 si, 0.0 st
%Cpu5 : 26.1 us, 2.6 sy, 0.0 ni, 70.3 id, 0.3 wa, 0.3 hi, 0.0 si, 0.3 st
KiB Mem : 41042384 total, 1621820 free, 6024132 used, 33396432 buff/cache
KiB Swap: 21946356 total, 21946308 free, 48 used. 9811332 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
34389 root 20 0 967380 57812 8156 S 91.7 0.1 243:41.66 java
4295 oracle 20 0 4517788 497680 9364 S 0.0 1.2 4:15.28 java Reply

Читайте также:  Сборка линукс своими руками

Hi All, is there a way to get top output for a given command only listing all CPU info also and write to a file.. Reply

@Jai, Please go through this following article, that will explain how to save top command output to a file in Linux. How to Save Top Command Output to a File Reply

Источник

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.

# high to low ➜ ~ top -o +%CPU # low to high ➜ ~ top -o -%CPU 

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

    Best linux commands articles:

    Источник

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