Linux Process and Service
Linux Process and Service
Process and Service
进程管理
查看进程
- ps option
- 查看正在执行的进程
- -a 显示当前终端全部进程
- -u 以用户的格式显示进程信息
- -x 显示后台进程运行的参数
- ps -aux | grep
condition- 过滤查看指定条件进程
- ps -aux | grep
- -e 显示所有进程
- -f 全格式
- ps -ef
- 以全格式显示当前所有的进程,查看进程的父进程
- ps -ef
- ps 查看进程输出内容格式
- PID: 进程识别号
- TTY: 终端机号
- TIME: 此进程所消耗的CPU时间
- CMD: 正在执行的命令或进程名
- pstree option
- 查看进程树
- -p 显示进程的PID
- -u 显示进程的所属用户
终止进程
- kill option
PID- -9 强制终止
- killall
process name- 根据进程名终止
服务管理
使用service
- service
server name[start | stop | restart | reload | status]
使用systemctl
- systemctl [start | stop | restart | reload | status]
server name
运行级别
- 常用运行级别
- level 0: 关机
- level 1: 单用户模式, 用于系统维护
- level 3: 多用户无界面, multi-user.target
- level 5: 多用户有界面 graphical.target
- systemctl get-default
- 查看默认运行级别
- systemctl set-default
level name(.target)- 设置默认运行级别
服务自启动
- 使用chkconfig设置指定运行级别下的自启动
- 查看自启动状态
- chkconfig –list | grep
server name - chkconfig
server name–list
- chkconfig –list | grep
- 修改在指定运行级别下的服务自启动状态
- chkconfig –level
numserver name[on | off]- 不写–level, 则为所有运行级别设置
- 设置后reboot生效
- chkconfig –level
- 查看自启动状态
- 使用systemctl设置开机自启动
- 查看自启动状态
- systemctl list-unit-files
- systemctl is-enabled
server name
- 修改服务开机自启动
- systemctl [enable | disable]
server name
- systemctl [enable | disable]
- 查看自启动状态
动态监控进程
- top option
- -d
second指定多少秒刷新一次, 默认3s - -i 不显示空闲和僵死进程
- -d
- top交互指令
- P: 以CPU使用情况排序
- M: 以内存的使用率排序
- N: 以PID排序
- q: 退出top
- u +
user name: 监控指定用户 - k +
PID: 终止进程
防火墙firewall
- firewall-cmd –permanent –add-port=
port/protocol- 打开端口
- firewall-cmd –permanent –remove-port=
port/protocol- 关闭端口
- firewall-cmd –reload
- 重新载入
- firewall-cmd –query-port=
port/protocol- 查看端口是否开放
监控网络状况
- netstat option
- -an: 按顺序排列输出
- -p: 显示哪个进程在调用
This post is licensed under CC BY 4.0 by the author.