进程
进程
进程(process)是资源分配的最小单位,它是操作系统进行资源分配和调度运行的基本单位。通俗理解,一个正在运行的程序就是一个进程。
- 独立性:进程是一个能独立运行的基本单位,同时也是系统分配资源和调度的独立单位
- 动态性:进程的实质是程序的一次执行过程,进程是动态产生,动态消亡的
- 并发性:任何进程都可以同其他进程一起并发执行
多进程的作用
# hello.py
def func_a():
print("任务A")
def func_b():
print("任务B")
func_a()
func_b()
以上代码func_a
执行完才能执行func_b
。如何让func_a和func_b同时运行,提升hello.py
程序的运行效率。
%%{init: {"flowchart": {"htmlLabels": false}} }%% flowchart BT subgraph ide1 ["主进程"] direction BT a(执行func_a) --> b(执行func_b) end A[hello.py] -- "默认创建" --> ide1 subgraph ide2 ["主进程"] direction BT a1("执行func_a") end subgraph ide3 ["子进程"] direction TB a2("执行func_b") end A2[hello.py] --"创建"--> ide2 A2 -- "创建" --> ide3