1. Search for processes
PS is the command used to view processes in Linux:
[Syntax]: PS [-EFL] [-T grouping table] [-u User table] [-G group table]
[Note]: displays the status of related processes.
1) pS A shows all programs under the current terminal, including those of other users.
2) PS-A shows all programs.
3) when listing programs in ps c, the real command name of each program is displayed without the path, parameter or resident service identifier.
4) the effect of this parameter is the same as that of the specified "A" parameter.
5) when listing programs, PS e displays the environment variables used by each program.
6) pS F uses ASCII characters to display the tree structure and express the relationship between programs.
7) the PS-H tree structure is displayed, indicating the relationship between programs.
8) PS-n shows all programs, except the programs under the ps command terminal.
9) pS displays the program status in the program signal format.
10) when listing programs in PS, it includes interrupted subroutines.
11) PS-T <terminal number> specifies the terminal number and lists the status of programs belonging to the terminal.
12) pS U displays the program status in user-based format.
13) pS X shows all programs, which are not distinguished by terminals.
Grep is the command for full-text search in Linux:
[Syntax]: grep [Option] mode [file...]
[Note]: searches for the mode in the specified file and displays all rows containing the mode. The mode is a regular expression. When using a regular expression, it is best to enclose it in single quotes ('). If the specified file is the default value, standard input is used. The regular expression can be:
. Match any character
* Match 0 or more * characters before
^ Match the beginning of a row
$ Match the end of a row
[] Matches any character in []. [] indicates the range,
For example, [A-Z] indicates any one of the letters A to Z.
\ Conversion character
The options in the command are:
-B: displays the block number.
-C only displays the total number of lines in the mode in each specified file
-Uppercase and lowercase letters in I Mode
-H does not display the file name in the include mode on this row.
-L only display the file name in the include Mode
-N: row number of the row in the display mode
-S: if the specified file does not exist or is unreadable, no error message is displayed.
-V: Display All rows that do not contain the Mode
[Example]:
Grep 'good' * search all files for rows containing the string 'good'
Grep '^ myline' mytext searches myline strings at the beginning of the mytext file.
SoGrep-V "grep"The command is used to find and display rows without the "grep" string.
WhileGrep "XXX"The command is used to find and display the line containing the "XXX" string.
WC is the command used to count characters in Linux:
[Syntax]: WC [-LWC] file...
[Description]: number of rows, characters, and characters in the statistical file. If no file is specified, the statistical standard input is used.
-L only count the number of rows
-W only count words
-C: Count only characters
[Example]:
WC-l file1 file2 the number of lines in the file1 and file2 statistical files
Ii. Terminate the processThe kill command is used to stop a process:
2) Format
Kill [-S Signal |-p] [-A] PID...
Kill-L [Signal]
3) Parameters
-S: Specifies the sent signal.
-P: analog transmission signal.
-L: Name List of the specified signal.
PID: ID of the process to be aborted.
Signal: indicates the signal.
4) Application Instances
(1) force stop (often used to kill) a process with the process ID 324:
# Kill-9 324
(2) Remove the deadlock in Linux
In Linux, a program crashes and is in a deadlock state. In this case, you do not need to restart the computer. You only need to stop (or close) the problematic program. When kill is on the x-window interface, the main program (except the crashed program) is generally started normally. Open a terminal and stop the problematic program there. For example, if the Mozilla browser program is locked, you can use the kill command to stop all programs that contain the mozolla browser. First, use the ps command to find the PID of the program, and then use the kill command to stop the program:
# Kill-sigkill xxx
Xxx indicates the process ID of the program with the mozolla browser.
(3) Use commands to recycle memory
We know that memory is very important to the system. memory recovery can improve system resources. The kill command can be used to abort programs that are out of track or do not have the corresponding programs for a long time. For example, if you use the top command to find a useless (zombie) process, you can use the following command:
# Kill-9 xxx
XXX is a useless process ID.
Run the following command:
# Free
The available memory capacity is increased.
(4) killall command
In Linux, A killall command is also provided to directly use the process name instead of the process ID number. For example:
# Killall-hup inetd