Centos7--14. Process Management

1. Basic introduction process

1) In LINUX, the program (codes) of each execution is called a process. Each process is assigned an ID number.
2) Each process will correspond to a parent, but the parent process can be replicated multiple sub-processes. For example, www server.
3) Each process may exist in two ways. Front and back, the so-called foreground process is currently on-screen user can enter
line operation. Background process is actually in operation, but the process can not be seen on the screen, usually performed using a background mode.
4) general system services are the future there is a background process, and will be resident in the system. Until just before the end of the shutdown.

2. The display process performed by the system

2.1 Description:

View instructions using
ps, general parameters using ps -aux

figure 1

figure 2

2.2 ps Detailed instructions

1) command: ps -aux | grep xxx, for example, I see no sshd service
2) Instructions

• System V 展示风格
• USER:用户名称
• PID:进程号
• %CPU:进程占用 CPU 的百分比
• %MEM:进程占用物理内存的百分比
• VSZ:进程占用的虚拟内存大小(单位:KB)
• RSS:进程占用的物理内存大小(单位:KB)
• TT:终端名称,缩写 .
• STAT:进程状态,其中 S-睡眠,s-表示该进程是会话的先导进程,N-表示进程拥有比普通优先
级更低的优先级,R-正在运行,D-短期等待,Z-僵死进程,T-被跟踪或者被停止等等
• STARTED:进程的启动时间
• TIME:CPU 时间,即进程使用 CPU 的总时间
• COMMAND:启动进程所用的命令和参数,如果过长会被截断显示

2.3 Application examples

Requirements: Display the parent of all the current process, view the process in full format
3

• ps -ef 是以全格式显示当前所有的进程
• -e 显示所有进程。-f 全格式。
• ps -ef|grep xxx
• 是 BSD 风格
• UID:用户 ID
• PID:进程 ID
• PPID:父进程 ID
• C:CPU 用于计算执行优先级的因子。数值越大,表明进程是 CPU 密集型运算,执行优先级会
降低;数值越小,表明进程是 I/O 密集型运算,执行优先级会提高
• STIME:进程启动的时间
• TTY:完整的终端名称
• TIME:CPU 时间
• CMD:启动进程所用的命令和参数

Questions: If we want to see the parent process ID of the sshd process is how much, how to query?

ps -ef | grep sshd
Figure 4

3. terminate the process kill and killall

3.1 Introduction:

If a process executed when half needs to be stopped, or has gone down a lot of system resources, then you can consider stopping the process.
Use the kill command to complete this task.

3.2 The basic syntax:

kill [选项] 进程号(功能描述:通过进程号杀死进程)

killall 进程名称 (功能描述:通过进程名称杀死进程,也支持通配符,这在系统因负载过大而变
得很慢时很有用)

3.3 Common Options

-9: 表示强迫进程立即停止

3.4 Best Practices

Case 1: Illegal kicked off a logged-on user
ps -aux | grep sshd
5

Case 2: terminate the Telnet service sshd, at the appropriate time to restart sshd service again
ps -aux | grep sshd
kill 3908
6

Case 3: terminate multiple gedit editor [killall, to terminate the process by process name]
7

Case 4: forced to kill a terminal
8

4. Review the process tree pstree

4.1 The basic syntax:

pstree [选项],可以更加直观的来查看进程信息

4.2 Common examples:

Case 1: Please show the process in the form of a tree pid
pstree -p
9

Case 2: Please show your progress in a tree in the form of user id
pstree -u

5. Service (Service) management

5.1 Introduction:

Service (service) is the essence of the process, but is running in the background, usually listening on a port, please wait for other programs
seeking, such as (mysql, sshd
firewalls, etc.), so we called daemon, Linux is very important points. [Original
processing] FIG
10

5.2 service management instructions

service 服务名 [start | stop | restart | reload | status]
After Centos 7.0, no longer use the service, but systemctl

5.3 Use case:

1) view the current status of the firewall, turn off the firewall and restart the firewall.

11

5.4 discuss the details

1) After closing or the firewall is enabled, effective immediately. [telnet test a port to]
12

2) entry into force of this way is only temporary, when restarting the system, or return to the previous set of services.
If you want to set up a service from the start or off the permanent, use chkconfig command

5.5 View service name

Method 1: Use setup -> System Services can be seen.
13

Mode 2: /etc/init.d/ Service Name
14

5.6 run-level services (runlevel)

查看或者修改默认级别:
vi /etc/inittab
Linux 系统有 7 种运行级别(runlevel):常用的是级别 3 和 5
• 运行级别 0:系统停机状态,系统默认运行级别不能设为 0,否则不能正常启动
• 运行级别 1:单用户工作状态,root 权限,用于系统维护,禁止远程登陆
• 运行级别 2:多用户状态(没有 NFS),不支持网络
• 运行级别 3:完全的多用户状态(有 NFS),登陆后进入控制台命令行模式
• 运行级别 4:系统未使用,保留
• 运行级别 5:X11 控制台,登陆后进入图形 GUI 模式
• 运行级别 6:系统正常关闭并重启,默认运行级别不能设为 6,否则不能正常启动

5.7 boot process descriptions

15

5.8 chkconfig command

Introduction
can be set to different operating levels for each service from the start / closed by chkconfig command

The basic syntax
1) 查看服务 chkconfig --list|grep xxx
16

2) chkconfig service --list name
17

3) chkconfig --level 5 service name on / off
set the sshd service in run level 5 is the case, do not self-starting.
18

5.9 Application examples:

1) Case 1: display the various operational levels for all services current system status
bash> chkconfig --list

2) Case 2: Check the status of running sshd service
bash> service sshd status

3) Case 3: sshd service is not set to start automatically in run level 5, to see what effect?
bash> chkconfig --level 5 sshd off

4) Case 4: When the run level is 5, turn off the firewall.
bash> chkconfig --level 5 iptables off

5) Case 5: In all operating levels, turn off the firewall
bash> chkconfig iptables off

6) Case 6: In all operating level, open the firewall
bash> chkconfig iptables on

5.10 Details

chkconfig 重新设置服务后自启动或关闭,需要重启机器 reboot 才能生效.

6 dynamic monitoring process

6.1 Introduction

top and ps command is very similar. They are used to show the process of being implemented. Top with ps biggest difference is, that the top
may update the running process execution time.

6.2 The basic syntax

top [选项]

6.3 Option Description

19

6.4 Application examples

Case 1. monitor a specific user
top: enter this command and press Enter to see the implementation process.
u: and enter the "u" Enter, and then enter a user name, you can

Figure 20

Case 2: terminates the specified process.
top: enter this command and press Enter to see the implementation process.
k: Then enter "k" Enter, then enter the number you want to end the process ID

Figure 21

Case 3: Specifies the system status update time (automatically updated every 10 seconds, 3 seconds by default):
the bash> Top 10 -d

6.5 Check System Network case netstat (important)

+ 基本语法
    `netstat [选项]`
     `netstat -anp`

+ 选项说明
    `-an 按一定顺序排列输出`
    `-p 显示哪个进程在调用`

+ 应用实例
    查看系统所有的网络服务
    *图22*![](https://img2018.cnblogs.com/blog/1595603/201908/1595603-20190829182145626-1013530742.png)



    请查看服务名为 sshd 的服务的信息。
    *图23*![](https://img2018.cnblogs.com/blog/1595603/201908/1595603-20190829182127448-330678001.png)

Guess you like

Origin www.cnblogs.com/zwxo1/p/11431362.html