Linux top commands sorted by memory consumption and sorted by CPU

Source: Internet
Author: User
Tags exit memory usage sort cpu usage

The Linux top command defaults to CPU-occupied sorting, and press m to switch to the sorted by memory footprint. This is system maintenance and computer memory maintenance. can switch. Different uses to achieve different effects. The following is a detailed description of these two.

p– the list of processes in the order of CPU usage size

m– the list of processes in the order of memory usage size

During system maintenance, you may need to look at the CPU usage at any time, and analyze the system condition according to the corresponding information. In CentOS, you can view CPU usage through the top command. When you run the top command, the CPU usage status is displayed in full screen mode, and it will be in a conversational pattern-with commands based on top, you can control how the display is displayed, and so on. The command to exit Top is Q (hit Q key once in top run).

Enter top on the command line to start up, and the full screen dialog mode of the tops can be divided into 3 parts: System Information Bar, command input bar, process list bar.

The first part-the top System Information Bar:

First line (top):

"14:55:59" is the current moment of the system;

"4 days, 5:52" for the system after the start of the current operation time;

"1 user" for the current user login to the system, or, more specifically, log on to the user's terminal number-the same user at the same time multiple terminals connected to the system will be considered as multiple users connected to the system, where the number of users will also be displayed as the number of terminals;

"Load average" is the average of the current system load, the following three values are 1 minutes ago, 5 minutes ago, 15 minutes before the average process, the general can be considered that the number of CPUs, the CPU will be more laborious load the current system contains processes;

Second line (Tasks):

Total is the current number of system processes;

"1 Running" is the number of processes currently running;

"One Sleeping" is the number of processes currently in the waiting state;

"0 stoped" is the number of system processes stopped;

"0 Zombie" for the number of recovered processes;

Third line (Cpus):

The current utilization rate of CPU is indicated respectively.

Line Four (MEM):

Represents the total amount of memory, current usage, amount of idle memory, and the amount of RAM used in the buffer;

Line Five (Swap):

Represents a category with line fourth (MEM), but this reflects the usage of swap partitions (swap). Typically, swap partitions (swap) are used frequently, and are considered to be the result of insufficient physical memory.

Part Two-internal command prompt bar in the middle section:

The top command allows you to control how the process is displayed through the top's internal commands. The internal command follows the following table:

s– Change the frequency of the screen update

l– closes or opens the first line of top information representation

T-closes or opens the first part the second line of Tasks and the third line Cpus the representation of information

m– closes or opens the first section the representation of the four-line Mem and fifth-line Swap information

Benzo vary thiazole The list of processes in the order of the PID size

p– the list of processes in the order of CPU usage size

m– the list of processes in the order of memory usage size

H-Display Help

Benzo vary Thiazole Set the number of processes displayed in the process list

q– Exit Top

s– Change the screen update cycle

Part Three-the bottom part of the Process list bar:

The PID-Differentiated process list updates periodically according to the set of screens. The top internal command controls how the display is displayed here.

In general, we have remote monitoring of the server maintenance, so that the server local terminal to run the top in real time, is a server to monitor the state of the server's fast and convenient one.

Ubuntu Process Management Method

PS Display current Process

Ps-l Display Details

Ps-u is displayed in the user's format

Related field Description

F process Status Flag

S Process Status Code

UID Process Performer ID

PPID (Parent process ID)

Priority of the PRI Process Execution (priority)

NI Process Execution Priority Nice value, negative values indicate higher priority

The amount of memory consumed by the SZ process

Wchan the address of a process or system call while waiting

%CPU CPU Usage percent

%mem Memory usage percent

VSZ Consuming virtual memory size

RSS consumes physical memory size

Start process begin time

Kill Delete Process

Kill PID Deletes the process of the specified PID

Kill-l See all the signals available for transmission.

Kill-9 PID Forced Delete process, the transmission is Sigkill signal

Kill-15 PID Forced Delete process, the transmission is sigterm signal

Kill-hup PID Restart Deamon process

Free View Memory usage status

Free-s 10 Check memory usage every 10 seconds

Nice set execution priority, -20~19,19 minimum

sudo nice–2 VI to set VI priority to-2

Renice Modify execution priority, -20~19,19 minimum

Top Dynamic Display Process

Press the "P" key to sort by CPU usage time

Press the "M" key to sort by how much memory is used

Press ' T ' key to sort by execution time

Press the "U" key to monitor specific users

Press the "K" key to delete the process

top-d 10 Specify Update time

Lsof-p View the files opened by the process

Jobs Command View background jobs

Ubuntu End Process Method

1, open the terminal

2, knock Ps-ef to find the number of the process (is the PID column)

3, Kill PID (if the PID is 123456, then kill 123456)

4, OK.

In the local Ubuntu Linux system running large software, or after a long time running the server, because some of the design of defective software, easy to appear suspended animation situation!

What should we do when the procedure is suspended from animation? In fact, this problem is actually simple and simple, the direct end of the process is not OK! Just like we did under Windows! Here are some ways to end a process under several Ubuntu Linux!

The safest way to kill a process

The safest way to kill a process is simply to use the KILL command, with no modifiers, no flags.

First use the PS-EF command to determine the PID to kill the process, and then enter the following command:

#kill-pid

Note: The standard KILL command usually achieves the purpose. Terminate the problematic process and release the resources of the process to the system. However, if a process starts a child process and kills only the parent process, the child process is still running and therefore consumes resources. To prevent these so-called "zombie processes", be sure to kill all of their child processes before killing the parent process.

You can also use the following command to determine which PID or ppid to kill the process

# Ps-ef | grep httpd

To end the process in the most elegant way

# kill-l PID

The-l option tells the kill command to end the process as if the user who started the process has logged off. When this option is used, the kill command attempts to kill the left child process as well. But this command is not always successful-it may still be necessary to manually kill the subprocess before killing the parent process.

Term signal

Sends a term signal to the parent process, trying to kill it and its child processes.

# kill-term PPID

Killall command

The killall command kills all processes within the same process group. It allows you to specify the name of the process to terminate, not the PID.

# Killall HTTPD

Stopping and restarting processes

Sometimes you just want to simply stop and restart the process. As follows:

# Kill-hup PID

This command shuts down the Linux gentle execution process and then restarts it immediately. This command is handy when you configure the application, and you can execute this command when you need to restart the process after modifying the configuration file.

Lore Kill-9 PID

Agreed to Kill-s SIGKILL

This powerful and dangerous command forces the process to terminate abruptly at run time, and the process cannot clean itself after it is finished. The hazard is that the system resources are not released normally and are not recommended unless otherwise available.

When using this command, be sure to confirm with ps-ef that there are no zombie processes left. Zombie processes can only be eliminated by terminating the parent process. If the zombie process is adopted by INIT, the problem is more serious. Killing the init process means shutting down the system.

If there is a zombie process in the system, and its parent process is init, and the zombie process consumes a lot of system resources, then you need to reboot the machine at some point to clear the process table.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.