Summary of Several Linux commands

Source: Internet
Author: User

1. pgrep command

Pgrep is a tool used to query processes by program names. It is generally used to determine whether a program is running. In server configuration and management, this tool is often used and simple and clear;


 # Ps parameter option program name

 Common Parameters

-L list the program name and process ID;

-The ID of the start of the O process;
-N indicates the ID of the process to terminate;


[root@localhost ~]# pgrep -lo httpd
4557 httpd

[Root @ localhost ~] # Pgrep-ln httpd
4566 httpd

[Root @ localhost ~] # Pgrep-l httpd
4557 httpd
4560 httpd
4561 httpd
4562 httpd
4563 httpd
4564 httpd
4565 httpd
4566 httpd

[Root @ localhost ~] # Pgrep httpd

2. ps command

View the process. The process status is displayed instantly and cannot be refreshed dynamically. To view dynamic process monitoring, run the TOP command.

PS commands are most commonly used to monitor the working conditions of background processes,

You can use this command to determine which processes are running and running, whether the process is terminated, whether the process is dead, and which processes are occupying excessive resources.

There are five processes in Linux:
1. Run (running or waiting in the running Queue)
2. interruption (in sleep, blocked, waiting for the formation or receipt of a signal of a condition)
3. Do not interrupt (do not wake up when receiving the signal or do not run, the process must wait until there is an interruption)
4. Stiff (the process has been terminated, but the process descriptor exists until the parent process calls wait4 () and is released after the system call)
5. Stop (the process stops running after receiving signals from sigstop, sigstp, sigtin, and sigtou)

Ps command options

A displays all processes on the terminal, including those of other users.

R only displays running processes.

X shows the process without any control terminal.

U displays the program status in user-based format.

-Aux: Show All itineraries containing other users

1) run the ps command directly.

PID tty Time Command

For example:

Log on to the system as root to view the current process status

$ PS

PID tty Time Command

5800 ttyp0 00:00:00 bash

5835 ttyp0 00:00:00 PS

2) pS aux

User PID % CPU % mem vsz RSS tty stat Start Time Command

For example:

$ PS u

User PID % CPU % mem usz RSS tty stat Start Time Command

Test 5800 0.0 0.4 1892 1040 ttyp0 s nov27-Bash

Test 5836 0.0 0.3 2528 856 ttyp0 R nov27 PS u

3. Top Command

Top-01:06:48 up, 1 user, load average: 0.06, 0.60, 0.48
Tasks: 29 total, 1 running, 28 sleeping, 0 stopped, 0 zombie
CPU (s): 0.3% us, 1.0% Sy, 0.0% Ni, 98.7% ID, 0.0% wa, 0.0% hi, 0.0% Si
Mem: 191272 k total, 173656 K used, 17616 K free, 22052 K Buffers
Swap: 192772 k total, 0 K used, 192772 K free, 123988 K cached

PID user PR NiVirt res SHRS % CPU % mem time + command
1379 root 16 07976 2456 1980S 0.7 1.3. 03 sshd
14704 root 16 0 2128 980 R 796 0.7. 72 top
1 root 16 0 1992 632 s 544 0.0. 90 init
2 root 34 19 0 0 s 0.0 0.0. 00 ksoftirqd/0
3 root RT 0 0 0 s 0.0 0.0. 00 watchdog/0



Virt: virtual memory usage

1. The virtual memory size required by the process, including the database, code, and data used by the Process
2. If the process requests 100 MB of memory but only uses 10 MB, it will increase by MB instead of the actual usage.

Res: resident memory usage resident memory

1. Memory size currently used by the process, excluding swap out
2. Sharing of other processes
3. If you apply for MB of memory, the actual usage of 10 MB will only increase by 10 MB, which is opposite to virt.
4. When the Library occupies memory, it only counts the memory size occupied by the loaded library files.

SHR: Shared Memory

1. In addition to the shared memory of processes, it also includes the shared memory of other processes.
2. Although the process only uses several shared library functions, it contains the size of the entire shared library.
3. Calculate the physical memory occupied by a process. formula: res-SHR
4. After swap out, it will be downgraded

The first line:
10:01:23Current System Time
126 days, the system has been running for 126 days, 14 hours, and 29 minutes (during this period, the system has not restarted)
2 users currentTwo users have logged on to the system.
Load average: 1.15, 1.42, 1.44 The three numbers after load average are1 minute, 5 minutes, 15 minutes of Load.

Load average data is Every 5 secondsCheck the number of active processes at a time, and then calculate the value according to the specific algorithm. If this number is divided by the number of logical CPUs, the system is overloaded when the result is higher than 5.

In a multi-processor system, the average load is determined by the number of kernels. In 100% load computing, 1.00 represents a single processor, while 2.00 represents two dual processors, so 4.00 indicates that the host has four processors. Row 2:
Task tasks (processes), the system now has a total of 183 processes, of which one is running, 182 are sleep, and 0 are stoped, zombie status (zombie) has 0.
Row 3: CPU status
6.7% usUser spaceCPU usage.
0.4% SYKernel spaceCPU usage.
0.0% percentage of CPU used by processes whose priorities have changed by Ni
92.9% ID idle CPU percentage
0.0% percentage of CPU occupied by wa Io wait
CPU usage of 0.0% Hi hardware interrupt (hardware IRQ)
The CPU usage percentage of 0.0% Si Soft Interrupt (software interrupts) is different from that of windows. If you do not understand the user space and kernel space, you need to be charged.
Row 4: memory status
8306544 k totalPhysical memoryTotal (8 GB)
7775876 K used EnabledMemory in useTotal (7.7 GB)
530668 K freeIdle memoryTotal (530 MB)
79236 K BuffersCache memory size(79 m)

Row 5: swap Partition
2031608 k totalTotal number of swap Areas(2 GB)
2556 K usedUsed swap ZoneTotal (2.5 MB)
2029052 K freeFree exchange zoneTotal (2 GB)
4231276 K cachedBuffer swap ZoneTotal (4 GB)

4. Kill command

The actual function of kill is to send signals to processes. The common format is kill-Sig PID. The Sig here can be the number corresponding to the signal or the signal name, for example, if you use the kill-9 PID to send a signal No. 9 to the city, the corresponding signal name of "9" is kill. Therefore, kill-9 is equivalent to kill-kill PID. The commonly used signal is int 2. This means that when you end a program with Ctrl + C under bash, Bash will send this signal to the process. The default signal is, the process ends when it receives the program. You can use the kill-int PID to send this signal. Quit 3: The signal sent when you end the program with Ctrl + \ In bash, after a process receives this signal by default, it also ends kill 9. This signal is called "forced kill" because it cannot change the action performed after the process receives this signal, and the process can only exit. (Although the two signals mentioned above are exited by default, the application can modify them to other actions by calling the signal system, for example, ignoring those two signals)

5. grep command

Grep-W pattern files: match only the entire word, not a part of the string (for example, match 'Magic ', not 'magical '),

-C: only counts matching rows are output.
-I: It is case-insensitive (only applicable to single characters ).
-H: When querying multiple files, the file name is not displayed.
-L: When querying multiple files, only names containing matching characters are output.
-N: displays matching rows and row numbers.
-S: the error message that does not exist or does not match the text is not displayed.
-V: displays all rows that do not contain matched text.
Main Parameters of the regular expression pattern:
\: Ignore the original meaning of special characters in regular expressions.
^: Match the start line of the regular expression.
$: Matches the end row of the regular expression.
\ <: Starts from the row that matches the regular expression.
\>: Ends with the row that matches the regular expression.
[]: A single character. For example, [a] indicates that a meets the requirements.
[-]: Range, such as [A-Z], that is, a, B, c Until Z all meet the requirements.
.: All single characters.
*: It can contain 0 characters.

Here are some special symbols used for search:
\ <And \> respectively indicate the start and end of a word.
For example:
Grep man * matches 'Batman ', 'manic', 'Man ', etc,
Grep '\ <man' * matches 'manic 'and 'man', but not 'Batman ',
Grep '\ <man \>' only matches 'man ', not other strings such as 'Batman' or 'manic.
'^': Indicates the first row of the matched string,
'$': Indicates the end of a matched string,

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: 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.