查看进程
回忆上次内容
- 上次先<kbd>ctrl</kbd> + <kbd>z</kbd> 挂起进程
![图片描述 [oeasy]python0032_杀死进程_进程后台运行不输出_nohup_ps_显示进程_后台运行](https://file.cfanz.cn/uploads/png/2022/12/21/14/8cLdR2ccB8.png)
- 程序继续跑起来
- 而且不断输出到标准输出流
- 甚至连<kbd>ctrl</kbd> + <kbd>c</kbd> 都无法结束进程了
- 这可怎么办呢?
- 只能新开一个终端想办法
查询进程
![图片描述 [oeasy]python0032_杀死进程_进程后台运行不输出_nohup_ps_显示进程_搜索_02](https://file.cfanz.cn/uploads/png/2022/12/24/14/647MZV2796.png)
进程
![图片描述 [oeasy]python0032_杀死进程_进程后台运行不输出_nohup_ps_显示进程_后台运行_03](https://file.cfanz.cn/uploads/png/2022/12/24/14/984f4N6cHb.png)
动手试试
![图片描述 [oeasy]python0032_杀死进程_进程后台运行不输出_nohup_ps_显示进程_搜索_04](https://file.cfanz.cn/uploads/jpeg/2022/12/24/14/8B11Q7902F.jpeg)
- 看起来上一个zsh就是pid为281的进程
- 记住281这个pid
搜索
![图片描述 [oeasy]python0032_杀死进程_进程后台运行不输出_nohup_ps_显示进程_python_05](https://file.cfanz.cn/uploads/png/2022/12/24/14/H205c0911e.png)
![图片描述 [oeasy]python0032_杀死进程_进程后台运行不输出_nohup_ps_显示进程_后台运行_06](https://file.cfanz.cn/uploads/jpeg/2022/12/24/14/7Z251d1K9B.jpeg)
杀意
- pid的编号可以通过ps -elf的结果中找到
- 找到上一个zsh的pid
- 就是刚刚的281
#杀死进程
kill -9 PID
- 发过去之后那个进程就要自尽 🥵
- 没有任何进程愿意接受着这个信号
- 君要臣死,臣不得不死
- 权限对进程是多么重要啊
- 但是接到了就要执行
- 阿啊阿啊阿啊·~ 💀
![图片描述 [oeasy]python0032_杀死进程_进程后台运行不输出_nohup_ps_显示进程_python_07](https://file.cfanz.cn/uploads/png/2022/12/24/14/dC32IdPX37.png)
zsh进程
#查询进程
#我们只要和zsh这个进程相关的
#把e去掉
ps -lf
![图片描述 [oeasy]python0032_杀死进程_进程后台运行不输出_nohup_ps_显示进程_后台运行_08](https://file.cfanz.cn/uploads/png/2022/12/24/14/7F8R48V7e1.png)
![图片描述 [oeasy]python0032_杀死进程_进程后台运行不输出_nohup_ps_显示进程_后台运行_09](https://file.cfanz.cn/uploads/png/2022/12/24/14/c22b50d8De.png)
启动更多新进程
![图片描述 [oeasy]python0032_杀死进程_进程后台运行不输出_nohup_ps_显示进程_python_10](https://file.cfanz.cn/uploads/png/2022/12/24/14/aLZ981OC2f.png)
suspend词源
![图片描述 [oeasy]python0032_杀死进程_进程后台运行不输出_nohup_ps_显示进程_搜索_11](https://file.cfanz.cn/uploads/png/2022/12/24/14/8KK8fe179b.png)
- 支撑;承受(sus+tain握住→在下面握住→支撑)
- susceptive 有接受力的;敏感的(sus+cept拿+ive→有拿下的能力→有接受力的)
-pend
![图片描述 [oeasy]python0032_杀死进程_进程后台运行不输出_nohup_ps_显示进程_搜索_12](https://file.cfanz.cn/uploads/png/2022/12/24/14/QQR1HVL7aG.png)
- de-, 向下,离开 -pend, 悬挂
- 即悬挂点
- 引申义依靠
- denpendent
- independent
- 词根词缀: ap- 来 , 临近
- -pend- 悬挂
- 垂→依附
- ex- 出 , 向外 + -pend- 支付
- spend
suspend
![图片描述 [oeasy]python0032_杀死进程_进程后台运行不输出_nohup_ps_显示进程_后台运行_13](https://file.cfanz.cn/uploads/png/2022/12/24/14/16d4P4eHJ5.png)
- 先运行再挂起还是有点麻烦
- 可以直接后台运行但是不输出到屏幕吗?
搜索
![图片描述 [oeasy]python0032_杀死进程_进程后台运行不输出_nohup_ps_显示进程_后台运行_14](https://file.cfanz.cn/uploads/png/2022/12/24/14/3ECQ2aEWI4.png)
![图片描述 [oeasy]python0032_杀死进程_进程后台运行不输出_nohup_ps_显示进程_搜索_15](https://file.cfanz.cn/uploads/png/2022/12/24/14/921134250b.png)
查询手册
![图片描述 [oeasy]python0032_杀死进程_进程后台运行不输出_nohup_ps_显示进程_python_16](https://file.cfanz.cn/uploads/png/2022/12/24/14/b2Z51266EN.png)
后台运行不输出
![图片描述 [oeasy]python0032_杀死进程_进程后台运行不输出_nohup_ps_显示进程_后台运行_17](https://file.cfanz.cn/uploads/png/2022/12/24/14/R36A6YSQF3.png)
- nohup python -u show_time.py > test.log 2>&1 &
- 0 – stdin (standard input,标准输入)
- 1 – stdout (standard output,标准输出)
- 2 – stderr (standard error,标准错误输出)
- 2>&1 解释:
- 将标准错误 2 重定向到标准输出 &1
- 标准输出 &1 再被重定向输入到 test.log 文件中
后台进程
![图片描述 [oeasy]python0032_杀死进程_进程后台运行不输出_nohup_ps_显示进程_搜索_18](https://file.cfanz.cn/uploads/png/2022/12/24/14/Ea0174aLA4.png)
总结
-
ps -elf
查看所有进程信息 -
ps -lf
查看本终端相关进程信息
-
kill -9 PID
给进程发送死亡信号
- 运行多个
python3 show_time.py
的话
- 各个进程独立
-
python3 show_time.py
大概 8+M - 各占内存
![图片描述 [oeasy]python0032_杀死进程_进程后台运行不输出_nohup_ps_显示进程_python_19](https://file.cfanz.cn/uploads/png/2022/12/24/14/9AYL8Z0H42.png)
- 我们下次再说!👋
- 蓝桥->https://www.lanqiao.cn/courses/3584
- github->https://github.com/overmind1980/oeasy-python-tutorial
- gitee->https://gitee.com/overmind1980/oeasypython
- 视频->https://www.bilibili.com/video/BV1CU4y1Z7gQ 作者:oeasy