A program is a collection of executable machine code and data that is stored on an external storage device, such as a hard disk. A process is a computer program that is in a dynamic state of execution in CPU and memory. Each program starts with one or more processes, such as the HTTPD program, which generates multiple processes to provide services when a large number of users visit the Web page.
One view process
1 PS: view static process information
Option: A displays all process information under the current terminal
U output process information in a user-oriented format
x displays process information for the current user under all terminals
-e Displays all process information in the system
-l display process information with long format
-F Displays process information in full format
[Email protected] ~]# PS #只显示当前用户会话中打开的进程
PID TTY Time CMD
2838 pts/0 00:00:00 Bash
5252 pts/0 00:00:00 PS
[[Email protected] ~]# PS aux #以列表的形式显示出进程信息
[Email protected] ~]# ps-elf #使用长格式显示进程的详细信息
[[Email protected] ~]# PS aux | grep mysqld #查看mysqld进程信息
2 Top: View process dynamic information
[email protected] ~]# Top
3 pgrep: Querying for specific process information
Option:-l long format output, query the name and process ID of all matching processes
-U queries a specific user's process
[[email protected] ~]# pgrep-l "My" process information #查询名称中包含 "my"
5531 Mysqld_safe
5633 mysqld
[Email protected] ~]# pgrep-l-u root #查询root用户的进程名称和ID号
4 Pstree: Viewing the process tree
Option:-A lists the complete command information
-U displays the corresponding user name
-p Show Process ID number
[Email protected] ~]# Pstree #显示进程树
[[email protected] ~]# Pstree-aup #显示进程树详细信息, including PID, user, command
[[email protected] ~]# pstree-aup MySQL #指定用户, lists the process structure opened by user MySQL
mysqld,5633--basedir=/usr--datadir=/var/lib/mysql--user=mysql--log-error=/var/log/mysqld.log--pid-file=/var/ Run/mysqld/mysqld.pid--socket=/var/lib/mysql/mysql.sock
├─{mysqld},5635
├─{mysqld},5636
├─{mysqld},5637
├─{mysqld},5638
├─{mysqld},5645
├─{mysqld},5646
├─{mysqld},5647
├─{mysqld},5648
└─{mysqld},5649
II. Management Process
1 &: Background START process
[Email protected] ~]# cp-r/etc/./& #进程后台启动
[[email protected] ~]# jobs-l #查看后台运行的进程,-l display PID number
2 Terminating a process
CTRL + C: Interrupts the process and sends a SIGINT signal to the process
To abort a process using a command:
Kill: The PID number is required as a parameter when terminating a process with kill
[email protected] ~]# kill 5633 #终止PID为5633的进程
[Email protected] ~]# kill-9 7582 #-9 means forced termination, cautious use
[[email protected] ~]# kill-s quit 7849 #向进程发送QUIT信号, calmly stop
Killall: Process can be terminated by process name
[[email protected] ~]# Killall master #终止进程, followed by process name
[[email protected] ~]# killall-9 Master #-9: Forced termination
[Email protected] ~]# killall-s QUIT mysqld #从容停止某项服务
Pkill: The process can be terminated based on the name of the process, the user running the process, and other properties
[Email protected] ~]# Pkill mysqld #终止进程
[Email protected] ~]# pkill-u "ZWJ" #终止用户zwj启动的进程,-9 forced termination
This article from "10,000 years too long, seize" blog, please be sure to keep this source http://zengwj1949.blog.51cto.com/10747365/1917070
Linux Process Management