Skip to content

Latest commit

 

History

History
199 lines (135 loc) · 3.75 KB

File metadata and controls

199 lines (135 loc) · 3.75 KB
Error in user YAML: (<unknown>): found a tab character that violate indentation while scanning a plain scalar at line 3 column 3
---
- oeasy Python 0270
- 这是 oeasy 系统化 Python 教程,从基础一步步讲,扎实、完整、不跳步。愿意花时间学,就能真正学会。
- 本教程同步发布在: 
	- 个人网站: `https://oeasy.org` 
	- 蓝桥云课: `https://www.lanqiao.cn/courses/3584` 
	- GitHub: `https://github.com/overmind1980/oeasy-python-tutorial` 
	- Gitee: `https://gitee.com/overmind1980/oeasypython` 
---

查看进程

回忆上次内容

  • 进程查询
    • ps -lf 查看 本终端相关的 进程信息
    • ps -elf 查看 所有进程的 信息
  • 杀死 进程
    • kill -9 PID 给进程发送死亡信号
  • 后台 运行
    • nohup python3 show.py>>s.log &

图片描述

  • 这些进程之间 是什么关系呢?🤔
#!/usr/bin/python
i = 0
import time
while True:
    i = i + 1
    print(i, "===", time.asctime())
    time.sleep(1)

具体查询

python3 show.py >> s.log &
  • zsh进程相关的 3 个进程
    • zsh
      • 当前的 shell环境
      • zsh进程
    • python3 sleep.py
      • 输出时间的python程序

图片描述

  • 可以观察进程(process)的细节吗?

进程细节

ps -lf
  • 查询进程的ps进程

图片描述

  • 能把结果输出到文件吗?

输出到文件

  • 先 输出重定向到process
    • 再打开process
ps -lf > process
vi process
  • 效果

图片描述

观察 父子关系

  • 可以查看到
    • 这进程之间有父子关系
    • pid 是指进程的 id
      • process id
    • ppid 是指 进程 id
      • parent process id

图片描述

  • ppidpid 的爸爸

图片描述

  • 进程有多大呢?

进程大小

  • pspython3
    • 都是 zsh的子进程

图片描述

  • python3这个进程 的 SZ什么意思?

SZ

man ps
  • 查看ps的手册manual

图片描述

查找SZ

/SZ
  • 进程核心镜像的物理页数
    • 占内存大小(SZ)
      • 4863 个 Page
      • 如果每个 page 多大 呢?
      • 具体需要多少内存呢?

图片描述

  • 这个vsz 和 rss 分别是什么意思?

实际分配

  • q退出manual
ps -o pid,ppid,sz,vsz,rss,cmd
  • 观察

图片描述

  • SZ 是欲分配的 内存
    • 用 页(4K) 来当单位

图片描述

  • VSZ 是欲分配的内存
    • 用 K 来当单位

图片描述

  • RSS 非交换区的内存 用 K 来当单位

图片描述

  • 也就是说 实际这个进程 也就
    • 9180K/1024
    • 8.94M
    • 8M+
  • python3.8 这个文件 在内存多大?

观察

ls -lh /usr/bin/python3.8
  • python3.8 这个文件
    • 不是本身 已经 5.3M

图片描述

  • 为什么 在内存里 还变大了?

总结

  • 除了 基础部分(内建 模块函数)之外
    • print()
    • ord()、chr()
    • int()、hex()、bin()
  • 还有 新加载的部分
    • show.py
    • import 进来的 time 这个 module

图片描述

  • time属于内建(built-in)的module

图片描述

  • 能看看内存里面具体长什么样子吗??🤔
  • 我们下次再说!👋

  • 本文来自 oeasy Python 系统教程。
  • 想完整、扎实学 Python,
  • 搜索 oeasy 即可。