Process Management
Summary
命令 | 說明 | 參數選項 | 備註 |
---|---|---|---|
ps aux | 顯示進程狀態 | a: all | BSD style |
u: effective user | |||
x command | |||
ps -elf | 顯示進程狀態 | e: all = A | SYSV style |
l: long format | |||
f: full-format listing | 可以顯示ppid | ||
pstree -u | 顯示進程所屬用戶 | ||
pstree -p | 顯示進程的pid | 結合|more 輸出 | |
Practice
ps aux
[root@tt ~]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 190908 3672 ? Ss 2019 5:18 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
root 2 0.0 0.0 0 0 ? S 2019 0:00 [kthreadd]
[root@tt ~]# ps au
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1529 0.0 0.0 115524 2156 pts/0 Ss 07:34 0:00 -bash
[root@tt ~]# ps x
PID TTY STAT TIME COMMAND
1 ? Ss 5:18 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
2 ? S 0:00 [kthreadd]
ps -elf
[root@tt ~]# ps -lef
F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD
4 S root 1 0 0 80 0 - 47727 ep_pol 2019 ? 00:05:18 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
pstree -u 顯示進程所屬用戶
[root@tt ~]# pstree -u
systemd─┬─AutonomyIDOLSer───20*[{AutonomyIDOLSer}]
├─CFS.exe─┬─2*[kvoop───{kvoop}]
│ └─29*[{CFS.exe}]
├─NetworkManager─┬─dhclient
│ └─2*[{NetworkManager}]
├─agentstore.exe───20*[{agentstore.exe}]
├─analytics(propel)───java───31*[{java}]
├─auditd───{auditd}
├─2*[autossh───ssh]
├─category.exe───14*[{category.exe}]
├─chronyd(chrony)
├─community.exe───13*[{community.exe}]
├─containerd─┬─2*[containerd-shim─┬─socat]
pstree -p 顯示進程的pid
[root@tt ~]# pstree -p | more
systemd(1)-±AutonomyIDOLSer(2708)-±{AutonomyIDOLSer}(2820)
| |-{AutonomyIDOLSer}(2854)
| |-{AutonomyIDOLSer}(2890)
| `-{AutonomyIDOLSer}(3682)
|-CFS.exe(2709)-±kvoop(3235)—{kvoop}(3236)
Service
Summary
命令 | 說明 | 參數選項 | 備註 |
---|---|---|---|
service firewalld status | 顯示服務狀態 | ||
systemctl status firewalld | 顯示服務狀態 | ||
/ect/init.d | 註冊服務地址 | ||
vim /etc/inittab | 運行級別 | 3:multi-user | |
systemctl get-default | 得到系統運行級別 | ||
netstat -anp | 查看所有的網絡服務 | a: all | |
n: numeric not hostname | |||
p: pid/program name | |||
chkconfig --list | 列出所有服務運行級別啓動狀態 | ||
chkconfig idm --list | 列出指定服務運行級別啓動狀態 | ||
chkconfig --level 2 idm off | 修改特定運行級別啓動狀態 | 設置所有級別,不要寫–level | |
運行級別設置成0或7 | 進入單用戶模式修改爲3 |
Practice
service firewalld status
[root@tt idm]# service firewalld status
Redirecting to /bin/systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
[root@tt idm]# service iptables status
Redirecting to /bin/systemctl status iptables.service
● iptables.service - IPv4 firewall with iptables
Loaded: loaded (/usr/lib/systemd/system/iptables.service; disabled; vendor preset: disabled)
Active: inactive (dead)
[root@tt idm]#
/ect/init.d
vim /etc/inittab
systemctl get-default
[root@ttl init.d]# systemctl get-default
multi-user.target
[root@ttl init.d]#
如果不小心將默認的運行級別設置成0或7,怎麼處理
進入單用戶模式
chkconfig --list
[root@ttl init.d]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
analytics 0:off 1:off 2:off 3:on 4:off 5:on 6:off
apidoc 0:off 1:off 2:off 3:on 4:off 5:on 6:off
autopass-ui 0:off 1:off 2:off 3:on 4:off 5:on 6:off
idm 0:off 1:off 2:off 3:on 4:off 5:on 6:off
idm-admin 0:off 1:off 2:off 3:on 4:off 5:on 6:off
[root@ttl init.d]#
chkconfig idm --list
chkconfig --level 2 idm off
[root@ttl init.d]# chkconfig idm --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
idm 0:off 1:off 2:on 3:on 4:off 5:on 6:off
[root@ttl init.d]# chkconfig --level 2 idm off
[root@ttl init.d]# chkconfig idm --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
idm 0:off 1:off 2:off 3:on 4:off 5:on 6:off
[root@ttl init.d]#
Monitor Process Dynamically
Top
命令 | 說明 | 參數選項 | 備註 | 例子 |
---|---|---|---|---|
top | -d delay time | unit : second | top -d 10 | |
-i idle | 不顯示任何閒置或殭屍進程 | top -i | ||
-p | 監控指定進程 | top -p 12447 | ||
top交互命令 | M | Memory 排序 | ||
u | 查看指定用戶 | |||
c | 切換顯示命令名稱和完整命令行 | |||
k | 終止一個進程 | |||
q | quit | |||
h | help |
Other
iptables
防火牆放行端口文件 /etc/sysconfig/iptables
[root@tt sysconfig]# pwd
/etc/sysconfig
[root@ttl sysconfig]# vim iptables1 # Generated by iptables-save v1.4.21 on Fri Jul 8 09:35:21 2016
2 *filter
3 :INPUT ACCEPT [0:0]
4 :FORWARD ACCEPT [0:0]
5 :OUTPUT ACCEPT [29:6509]
6 -A INPUT -i lo -j ACCEPT
7 -A INPUT -p icmp -j ACCEPT
8 -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
9 -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
12 -A INPUT -p tcp -m tcp --dport 9800 -j ACCEPT
13 -A INPUT -p tcp -m tcp --dport 9700 -j ACCEPT