Article Directory
1. Procedures and processes
1.1 The relationship between procedures and processes
- Program
Executable code and data stored in hardware, CD-ROM and other media
Statically stored code - Process
Program code running in CPU and memory
Dynamically executed code
Parent and child processes
Each program can create one or more processes
1.2 View process information
1.2.1 ps command
Role: View static process statistics
[root@localhost~]# ps aux
[root@localhost~]# ps -elf
Common options
Options | Description |
---|---|
a | Display all information under the current terminal |
u | Display process information in a user-oriented format |
x | Display the process information of the current user in all terminals |
-e | Display all information in the process |
-l | Use long format information process information |
-f | Display process information in full format |
1.2.2 top command
Role: View the rankings with higher CPU and memory usage, display dynamic information
[root@localhost~]# top
1.2.3 pgrep command
Role: View process information
[root@localhost~]# pgrep 选项 对象
Common options
Options | Description |
---|---|
-l '“xxx” | The output process name contains the process and process number of xxx |
-U aaa | Output process and process number run by user aaa |
-t pts / 0 | Output the process and pid number running on the pts/0 terminal |
1.2.4 pstree command
Role: query process tree
[root@localhost~]# pstree -acp
Common options
Options | Description |
---|---|
a | Complete command information |
u | List the corresponding username |
p | List its corresponding pid number |
Second, the operation of the process
2.1 How to start the process
2.1.1 Manual start
- Start in the foreground The
user enters commands and executes the program directly. - Start
in the background Add the "&" symbol at the end of the command line.
2.2.2 Schedule start (planned task)
at command
Function: Use the at command to perform a one-time scheduled task.
[root@localhost~]# at HH:MM yyyy-mm-dd
[root@localhost~]# atq ## 查看未执行的任务
[root@localhost~]# atrm 1 ## 删除第二条任务
Crontab command
Function: Repeat the command operation specified by the user according to the preset time period (minutes, hours, days...).
crontab -e ## 进入编辑任务计划
crontab -l ## 查看任务计划
crontab -r ## 删除任务计划
The format of crontab task configuration:
the special representation of time value:
character | Means |
---|---|
* | Indicates any time within the range |
, | Represents multiple discrete time points in an interval |
- | Represents a continuous time range |
/ | Specify the time frequency of the interval |
The crontab command is a periodic scheduled task
The main configuration files are:
Attributes | File or directory address |
---|---|
Global configuration file | /etc/crontab |
System default settings | /etc/cron.*/ |
User-defined settings | /var/spool/cron/ username |
2.2 Terminate the operation of the process
ctrl+c key combination
Command being executed by the terminal
ctrl+z key combination
Suspend the current task, that is, transfer to the background and stop running
kill, killall commands
kill is used to terminate the process of the specified PID number
killall is used to terminate all processes of the specified name
-9 option is used to force termination
pkill command
Terminate the corresponding process according to specific conditions
Common options
Options | Description |
---|---|
-U | Terminate the corresponding process according to the user name to which the process belongs |
-t | Terminate the corresponding process according to the terminal where the process is located |
2.3 View and restore process
jobs command
View the task list in the subject background
fg command
Restore the background task to the foreground, you can specify the task number