$ ls ~yifei/notes/

Python 的多线程和多进程

Posted on:

Last modified:

最原始的 fork

import os
pid = os.fork()
if pid > 0:
  print("parent process")
elif pid == 0:
  print("child process")
else:
  print("error create process")

在使用 os.kill 之后,还需要使用 waitpid 来处理子进程状态,否则就会变成僵尸进程。僵尸进程一直持有系统资源的进程状态,直到父进程回收处理。

import signal
os.kill(pid, signal.SIGTERM)
ret = os.waitpid(pid, 0)

参考

  1. https://mp.weixin.qq.com/s/mpW0Ex9X-0rQEyrt5titgw

© 2016-2022 Yifei Kong. Powered by ynotes

All contents are under the CC-BY-NC-SA license, if not otherwise specified.

Opinions expressed here are solely my own and do not express the views or opinions of my employer.