1、top Command Introduction

top Orders are used to Dynamic display Commands for processes in the system .

[[email protected] ~]# top [ Options ]
Options :
-d Number of seconds : Appoint top The command is updated every few seconds . The default is 3 second .
-b: Use batch mode output . In general, and "-n" The options apply , Used for holding top Command to redirect to file .
-n frequency : Appoint top The number of times the command was executed . In general, and “-b” The options apply .
-p: Appoint PID. Just look at one PID The process of .
-s: send top Run in safe mode , Avoid mistakes in interaction mode .
-u user name : Listen to only one user's progress .

demonstration :

stay top Commands that can be executed in command interaction mode :

  • ? or h: Display help for interactive mode .
  • P: With CPU Usage sort , This is the default .
  • M: Sort by memory usage .
  • N: With PID Sort .
  • T: according to CPU The cumulative operation time sequence of , Also is to use TIME+ Item sorting
  • k: according to PID Number , Give a signal to a process . Usually used to terminate a process , The signal 9 Is a forced termination signal .
  • r: according to PID Number , Prioritize a process (Nice) value .
  • q: sign out top command .

Tips : Press any key to return to top The initial interactive interface of the command .

2、top Order sample

perform top Command to view the results :

[[email protected] ~]# top
# The results are as follows 
top - 19:16:08 up 2 day, 10:34, 2 users, load average: 0.12, 0.06, 0.06
Tasks: 112 total, 1 running, 111 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.2%us, 0.2%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1906280k total, 467692k used, 1438588k free, 59528k buffers
Swap: 511996k total, 0k used, 511996k free, 232692k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
5113 root 20 0 15032 1228 936 R 0.7 0.1 0:00.34 top
1 root 20 0 19344 1548 1232 S 0.0 0.1 0:02.63 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd
3 root RT 0 0 0 0 S 0.0 0.0 0:00.38 migration/0
4 root 20 0 0 0 0 S 0.0 0.0 0:00.14 ksoftirqd/0

top The output of the command is dynamic , The default for each 3 Refresh every second .

The output of the command is mainly divided into two parts :

  • The first part is the first five lines , It shows the resource usage of the whole system , We judge the health status of the server through these outputs .
  • The second part starts from the sixth line , Displays information about the processes in the system .

3、top Command output item interpretation

(1) Description of the first part

  • The first line of information is task queue information .

    Content explain
    19:16:08 Current system time .
    up 2 day, 10:34 Running time of the system , This machine is running 2 God 10 Hours 34 minute .
    2 users Two users are currently logged in .
    load average: 0.12, 0.06, 0.06 The system is before 1 minute ,5 minute ,15 Average load in minutes .
    If CPU It's a single core , Then this number exceeds 1, It's high load .
    If CPU It's a four core , Then this number exceeds 4, It's high load .
    ( This average load is entirely judged by personal experience ,
    It is generally believed that it should not exceed the server CPU The number of nuclear .)
  • The second behavior is process information .
    Content explain
    Tasks: 112 total The total number of processes in the system .
    1 running Number of running processes .
    111 sleeping The process of sleep .
    0 stopped The process being stopped .
    0 zombie Zombie process . If not 0, Need to check the zombie process by hand .
  • Third act CPU Information .
    Content explain
    Cpu(s): 0.2%us User mode CPU percentage .
    0.2%sy The system mode occupies CPU percentage .
    0.0%ni Change the priority of the user process occupied by CPU percentage .
    99.7%id Free CPU Of CPU percentage .
    0.0%wa Waiting for input / Occupation of the output process CPU percentage .
    0.0%hi Hard interrupt request service occupied CPU percentage .
    0.0%si The soft interrupt request service occupies CPU percentage .
    0.0%st stSteal time) Percentage of virtual time . When there is a virtual machine , fictitious CPU Wait for the actual CPU Percent of time .
  • The fourth behavior is physical memory information .
    Content explain
    Mem: 1906280k total The total amount of physical memory , Company KB.
    467692k used The amount of physical memory that has been used .
    1438588k free The amount of free physical memory , We use virtual machines , All in all, only 2GB Memory , So only 1438MB Left and right of free memory .
    59528k buffers The amount of memory used as a buffer .
  • The fifth behavior is exchange partition (swap) Information .
    Content explain
    Swap: 511996k total Swap partition ( Virtual memory ) The total size of .
    0k used The size of the interaction partition that has been used .
    511996k free The size of the free swap partition .
    232692k cached The size of the interaction partition as the cache .

explain :

Focus on the output items

  • load average:cpu Previous load pressure .
  • 99.7%id:cpu Free .
  • Mem:free: Free memory space .
  • Swap:free:Swap Free space .

The above options can roughly judge the pressure of the server .

(2) Description of the second part

The output of the second part , Mainly system process information .

This section and ps The output of the command is similar , Only if it is executed in the terminal top command , Can't see all the processes , By default, press cpu The occupancy rate of , So by default, you can only see cpu The process at the top of the proportion .

for example :

 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
5113 root 20 0 15032 1228 936 R 0.7 0.1 0:00.34 top
  • PID: process ID.
  • USER: The user to which the process belongs .
  • PR : priority , The smaller the value, the higher the priority .
  • NI: priority , The smaller the value, the higher the priority .
  • VIRT: The size of the virtual memory used by the process , Company KB.
  • RES: The size of the physical memory used by the process , Company KB.
  • SHR: Shared memory size , Company KB.
  • S: Process status .
  • %CPU: The process takes up CPU Percent of .
  • %MEM: Percentage of memory occupied by the process .
  • TIME+: The process accounts for a total of CPU Time .
  • COMMAND: Process command name .

4、top Common examples of commands

(1) Only view PID by 5470 Of sshd The process of

[[email protected] ~]# top -p 5470
top - 20:48:41 up 12:07, 3 users, load average: 0.00, 0.02, 0.08
Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.0%us, 0.2%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.2%si, 0.0%st
Mem: 1906280k total, 470252k used, 1436028k free, 59528k buffers
Swap: 511996k total, 0k used, 511996k free, 232744k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 5470 root 20 0 99.7m 4148 3156 S 0.0 0.2 0:00.40 sshd

(2) Press "k" Key to terminate a process

Enter into top Command interface , Press k key , You will be prompted to enter the process you want to kill PID.

Press enter twice to kill the specified process .( This way of killing processes is not often used )

Now let's xinetd Process, for example :

Press enter twice ,xinetd The process is kill It fell off , wait for 3 seconds .

(3) How to use top Command view Linux All processes in

If... Is executed at the operating terminal top command , You can't see all the processes in the system , All you see by default is CPU The process at the top of the proportion . If we want to see all the progress , You can put top The result of the command can be redirected to the file .

however top The command runs continuously , It's time to -b and -n Options. , The specific command is as follows :

# Give Way top The command is executed only once , Let me save the results to top.log In file . So you can see all the processes 
[[email protected] ~]# top -b -n 1 > /root/top.log explain :
-b : You can make top Command content output .
-n : Appoint top The number of times the command was executed ( Refresh once ).

『 Forget when you learn 』Linux System management — 83、Linux View of processes in (top command ) More articles about

  1. 『 Forget when you learn 』Linux Basics — 1、UNIX System introduction

    Catalog ( One )UNIX System introduction 1.UNIX System development history 2.UNIX Major releases ( Two )GNU plan 1.GNU Plan Introduction 2. why Stallman Will initiate this GNU What about the plan ? 3.GNU General public license for : ...

  2. Linux System detection tool in top command

    Linux System detection tool in top command In this paper, from :https://www.cnblogs.com/zhoug2020/p/6336453.html First introduced top The meaning of some fields in : VIRT:virtua ...

  3. Linux Course ---12、linux In memory instructions (top What is the function of the order )

    Linux Course ---12.linux In memory instructions (top What is the function of the order ) One . summary One sentence summary : top Watch the process in real time . Memory and CPU situation 1. The computer is slow to respond , What comes to mind first ? Memory 2.linux ...

  4. linux Common process and memory optimization commands on

    process ps command f Show in a tree structure u Show details a Show all processes -A Show all processes -u user name Is to display the process under the user -l More process details Example 1. Show in a tree structure root Details of the process under the user ...

  5. 20170915 linux System management training

    Process management Program : It's usually a binary program in a storage medium ( Such as CD . Hard disk . floppy disk . Tape, etc ), In the form of a physical file : process : Running programs , When the program is triggered , The rights and properties of the performer . The program code and all the data of the program will be loaded into ...

  6. Linux System management 10—— Process and schedule task management

    Linux System management 10—— Process and schedule task management One . The relationship between program and process 1. Program · Save on hard disk . Executable code and data in media such as CD · Statically saved code 2. process · stay CPU And the program code running in memory · Dynamic execution generation ...

  7. linux Learning eight -Linux Local performance monitoring

    Linux Optimize 1. See if the disk is full ( Is the root directory full ). Is the memory full .CPU Is it full Check if the disk is full , Use df -h   Look at disk usage Check memory usage  free -m Pay special attention to swap How much? ...

  8. 《Linux operating system 》Linux A complete collection of common command operations

    Preface Before learning commands, learn how we should learn linux command . Almost every command has parameters , What is the meaning of each parameter , Not all of us can remember , So we must have a way to know the meaning of each parameter under each command . life ...

  9. linux System top Command to view system status

    Linux The system can go through top Command to view the system's CPU. Memory . The elapsed time . Swap partition . Thread of execution, etc . adopt top Command can effectively find out where the system defects are . It's not enough memory .CPU Not enough processing power .IO Reading and writing too high . Use SSH ...

  10. Linux top Order sorting

    In the process of system maintenance , You may need to check at any time CPU Usage rate , And according to the needs of the corresponding information analysis system . stay Linux in , Can pass top Order to see CPU Usage . function top After the command ,CPU The usage status will change to ...

Random recommendation

  1. oracle A complete collection of query statements

    1. Investigate oracle The character encoding format of the database select * from v$nls_parameters t where t.PARAMETER='NLS_CHARACTERSET'; If you find out ZH ...

  2. C# Get local IP And wireless networks ip

       1 private void GetIP()   2 { 3 string hostName = Dns.GetHostName();// Local name 4 //System.Net.IPAddress ...

  3. ubuntu matplotlib install

    sudo apt-get install python-numpy // must sudo apt-get install python-matplotlib // must

  4. About TFS2012 Unable to send alert email

    A few days ago, the company's TFS from 2010 Upgrade to 2012, The whole process went through 3 Hours , The process was relatively smooth . After the upgrade, I'm greedy for all kinds of new functions , Sigh that knowledge is really less hated when it is used , Only one by one to explore . One of them “ alert ” I was impressed by the function of ( ...

  5. Dynamic agent double swordsman --JDK Proxy And CGLIB

    background : People who have studied design patterns know that there are two implementation schemes of agent pattern : 1. Interface implementation ( Or inherit the abstract class ) Core code snippet ProxySubject-->>doOperation() //dosomet ...

  6. BZOJ 3282 Tree Link-Cut-Tree(LCT)

    The main idea of the topic : Given N Points and the weight of each point , I want you to deal with the next M Operations . Operation has 4 Kind of . Operation from 0 To 3 Number . Point from 1 To N Number . 0: Followed by two integers (x,y), The representative asked from x To y The weight of the point on the path of xor and . Guarantee x To y ...

  7. cursor Of moveToNext() And moveToFirst()

    String sql = "select count(*) as c from sqlite_master where type ='table' and name ='" + t ...

  8. sort- Bucket sort

    void list_insert(list<int> &t,int num) { auto iter=t.begin(); for(;iter!=t.end();++iter) { ...

  9. Python String method in

    Python String method in The string class is str Provides many useful ways to manipulate strings . say concretely , We will discuss the following methods . Search for substrings within a string . Test string . Format string . Convert string . Review the previous chapters , Method ...

  10. vue.js Jump about routing

    1. route demo Example <div id="app"> <h1>Hello App!</h1> <p> <!-- Use route ...