今天来聊聊Linux-进程及服务的控制

进程及服务的控制
1.什么是进程

系统中正在运行的程序

2.图形的进程查看方式
命令:
gnome-system-monitor

3.查看进程的命令

ps
     a    //当前环境相关
    -a    //在当前终端中运行的进程,但不包含当前环境信息
    -A|-e    //系统所有进程
     x    //查看含有输出端的进程
     f    //查看进程的从属关系
     u    //进程的所有人

ps ax -o comm,nice,%cpu,men,pid,user,group,stat |head -n 6 |tail -n 5 //查看前五行进程信息

ps ax --sort=%cpu |head -n 6 |tail -n 5 (按cpu大小正序,前五行)

ps ax --sort=-%cpu |head -n 6 |tail -n 5 (按cpu大小倒序,前五行)

4.进程的优先级

进程状态

S        //进程状态
s        //此进程顶级进程
T        //进程是暂停
<        //进程的优先级高
N        //进程优先级低
l        //进程在内存中有锁定空间

renice -n -5 pid    //修改进程优先级

nice -n -5 命令 &    //指定优先级开启进程

5.进程前后台的调用

Ctrl+z        //将占用终端的进程后台挂起
Ctrl+c        //将占用当前终端的进程结束
fg jbosnum    //第jobsnum个进程调回前台
bg jbosnum    //第jobsnum个进程在后台进行
jobs        //查看所有后台进程

6.信号

1 //进程不停止情况下重新加载配置
2 //清除进程在内存中的数据
3 //清除鼠标在内存中的数据
9 //强行结束某个进程
15 //正常关闭进程
18 //运行停止的进程
19 //暂停进程,不能被阻塞
20 //暂停进程

发起信号:
kill -信号 pid
killall -信号 进程名称

7.服务的控管

systemctl start sshd //开启
systemctl status sshd //状态显示

systemctl stop sshd //关闭

systemctl restart sshd //重起
systemctl enable sshd //开机自动开启
systemctl disable sshd //取消自动开启
systemctl list-units //列出所有服务的状态(图片显示了部分)

systemctl list-unit-files //列出系统中服务开机状态

systemctl list-dependencies //列出服务的依赖关系

systemctl mask sshd //冻结
systemctl unmask sshd //解冻

systemctl set-default multi-user.target //开机不开启图形界面
systemctl graphical.target //开机开启图形

猜你喜欢

转载自blog.51cto.com/13962326/2176365