进程是启动的可执行程序的一个指令
程序是一个静态的二进制文件,进程是程序运行的过程
[root@tianqinwei test]# sleep 5 --- 等待命令退出[root@tianqinwei test]#
[root@tianqinwei test]# sleep 5 &
[1] 30687
[root@tianqinwei test]#
例:交互进程和守护进程
[root@tianqinwei test]# read -p "input name:" name --- 交互进程
input name:student[root@tianqinwei test]# systemctl enable --now vdo.service --- (启动系统服务)守护进程
在多任务处理操作系统中,每个CPU(或核心)在一个时间点上只能处理一个进程。在进程运行时,它对CPU 时间和资源分配的要求会不断变化,从而为进程分配一个状态,它随着环境要求而改变
[root@tianqinwei ~]# w19:14:36 up 2 days, 1:02, 2 users, load average: 0.10, 0.04, 0.01
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.174.1 Sat18 1.00s 0.20s 0.01s w
root pts/1 192.168.174.1 18:19 4.00s 0.02s 0.01s -bash
信息含义:
查看个别用户信息:w [用户名]
<1> 常用选项:
-a | 显示所有用户的进程 |
-u | 显示用户名和启动时间 |
-x | 显示没有控制终端的进程 |
-e | 显示所有进程,包括没有控制终端的进程 |
-l | 长格式显示 |
-w | 宽行显示,可以使用多个 w 进行加宽显示 |
-f | 做一个更完整的输出 |
<2> 常用命令:
[root@tianqinwei ~]# ps -ef
[root@tianqinwei ~]# ps aux
<3> 案例:
例1:将占cpu的前10个进程列出来
例2:自定义显示进程信息
[root@tianqinwei ~]# pgrep sshd --- 多行显示
994
2321
2341
[root@tianqinwei ~]# pidof sshd --- 单行显示
2341 2321 994
<1> 常用选项
-d | 后面可以接秒数,就是整个进程界面更新的秒数,默认是5秒 |
-b | 以批次的方式执行top,还有更多的参数可用。通常会搭配数据流重定向来将批处理的结果输出为文件 |
-n | 与-b搭配,进行几次top的输出结果 |
-i | 不显示闲置或者僵死的进程信息 |
-c | 显示进程的整个命令路径,而不是只显示命令名称 |
-s | 使top命令在安全模式下运行,此时top的交互式指令被取消,避免潜在危险 |
-p | 指定某些个PID来进行查看检测 |
<2> 案例
设置进程刷新时间:
[root@tianqinwei ~]# top -d 2 --- 过两秒刷新一次
查看指定进程的动态信息:
[root@tianqinwei ~]# top -d 1 -p 10126 --- 查看进程号10126的进程每秒的动态信息
将信息写入文件:
[root@tianqinwei ~]# top -d 1 -b -n 2 > a.txt --- 每过一秒将两次top信息写入到文件中
编号 | 信号名 |
1)SIGHUP | 重新加载配置 |
2)SIGINT | 键盘中断^C |
3)SIGQUIT | 键盘退出 |
9)SIGKILL | 强制终止 |
15)SIGTERM | 终止(正常结束),缺省信号 |
18)SIGCONT | 继续 |
19)SIGSTOP | 停止 |
20)SIGTSTP | 暂停^Z |
例1:终止进程
[root@tianqinwei ~]# pidof httpd
31756 31755 31754 31753 31752
[root@tianqinwei ~]# kill -9 31756 --- 强制终止进程
[root@tianqinwei ~]# pidof httpd
53823 31755 31754 31753 31752
例2:终止httpd的所有进程
[root@tianqinwei ~]# pidof httpd
53823 31755 31754 31753 31752
[root@tianqinwei ~]# killall httpd --- 为所有httpd进程发送信号
[root@tianqinwei ~]# pidof httpd
案例:
[root@tianqinwei ~]# sleep 200 --- 运行程序,将前台运行的程序挂起在后台并^Z中止
^Z
[1]+ Stopped sleep 200
[root@tianqinwei ~]# jobs --- 查看后台作业
[1]+ Stopped sleep 200
[root@tianqinwei ~]# fg 1 --- 将作业1调回前台后,再^Z在后台挂起中止
sleep 200
^Z
[1]+ Stopped sleep 200
[root@tianqinwei ~]# bg 1 --- 将作业1在后台运行
[1]+ sleep 200 &
[root@tianqinwei ~]# jobs --- 查看后台作业
[1]+ Running sleep 200 &
[root@tianqinwei ~]# kill %1 --- 中止后台作业1的进程
[root@tianqinwei ~]# jobs
[1]+ Terminated sleep 200