Process management
1. Basic introduction to the process
- In Linux, each executed program and code becomes a process. Each process is assigned an ID number. A Simple Explanation of Processes and Threads
- Each process corresponds to a parent process, and the parent process can replicate multiple child processes.
- Each process may exist in two forms. Foreground and background, the foreground process is the operation that can be performed on the current screen; the background process is actually operating, but because the process cannot be seen on the screen, it is usually executed in the background mode.
- General system services exist in the form of background processes, and because the processes cannot be seen on the screen, they are usually executed in the background mode.
2. Display the process executed by the system
ps [选项]
: Displays the status of the current process (process).
Options
parameter | Function |
---|---|
-a |
Display all process information of the current terminal |
-u |
Display process information in user format |
-x |
Display the parameters of the background process running |
-e |
show all processes |
f |
full format |
Example
View progress
[root@wcl ~]# ps -aux|more USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 2 0.0 0.0 0 0 ? S 4月27 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S 4月27 0:00 [ksoftirqd/0] root 5 0.0 0.0 0 0 ? S< 4月27 0:00 [kworker/0:0H] ……省略部分结果
Pay attention to the second line above; let's introduce the specific meaning of each column name in it
-
column name meaning USER user name PID Process ID %CPU The percentage of CPU used by the process %MEM The percentage of physical memory used by the process VSZ The size of virtual memory occupied by the process (KB) RSS Physical memory size occupied by the process (KB) TTY terminal used STAT Process status; S: sleep; R: running, etc. START start time of the process TIME CPU time, which is the total time the process uses the CPU COMMAND Commands and parameters used to start the process
Display all current processes in full format, and see the parent process of the process
ps -ef | more
[root@wcl ~]# ps -ef |more UID PID PPID C STIME TTY TIME CMD root 3 2 0 4月27 ? 00:00:00 [ksoftirqd/0] root 5 2 0 4月27 ? 00:00:00 [kworker/0:0H] ... ...//省略剩余结果
Note: PID is the process ID; PPID: is the parent process ID
View sshd process
ps -ef | grep sshd
3. Terminate the process kill and killall
You want to stop the process halfway, or because the process consumes a lot of system resources. We use the kill command to accomplish this task.
kill [选项] 进程号
: kill process by process number
killall 进程名称
: Kill process by process name, wildcards are also supported
Common options
Options | Function |
---|---|
-9 |
Force the process to stop immediately |
Example
Kick off an illegal login user
[root@wcl ~]# ps -aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 2 0.0 0.0 0 0 ? S 4月27 0:00 [kthreadd] root 16628 0.0 0.0 150424 5860 ? Ss 17:26 0:00 sshd: root@pts/3 root 16630 0.0 0.0 116316 2908 pts/3 Ss 17:26 0:00 -bash root 16651 0.0 0.0 189604 2364 pts/3 S 17:26 0:00 su jack jack 16652 0.0 0.0 116328 2928 pts/3 S+ 17:26 0:00 bash
Note: we kick user jack out here
kill 16651
At this moment, the following paragraph will appear in the jack login window
[jack@wcl root]$ Session terminated, killing shell... ...已杀死。 [root@wcl ~]#
Force kill terminal 199
kill -9 199
Fourth, view the process tree pstree
You can view the process information more intuitively; here I don't have this command in my system for the time being, and I won't record it for the time being.
Installation instructions After
minimal installation of centos, use pstree to display the process tree, prompting that there is no such command.
It turns out that it is not installed, and psmisc needs to be installed
yum install psmisc
Improve it later! ! !
to be continued… …