进程

进程

进程(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