더북(TheBook)
# Chapter 4/child_processes.py
import os
from multiprocessing import Process

def run_child() -> None:
    print("자식: 나는 자식 프로세스야")
    print(f"자식: 내 PID: {os.getpid()}")
    print(f"자식: 내 부모의 PID: {os.getppid()}")

def start_parent(num_children: int) -> None:
    print("부모: 나는 부모 프로세스야")
    print(f"부모: 내 PID: {os.getpid()}")
    for i in range(num_children):
        print(f"{i} 번째 프로세스를 시작")
        Process(target=run_child).start() ----- ➊

if __name__ == "__main__":
    num_children = 3
    start_parent(num_children)

신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.