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