From 8f4e69ad9557555c1869662114aa9b1909889d6e Mon Sep 17 00:00:00 2001 From: chzhang Date: Thu, 1 Dec 2022 07:22:27 +0800 Subject: multiprocess --- threads/about_process.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 threads/about_process.py diff --git a/threads/about_process.py b/threads/about_process.py new file mode 100644 index 0000000..eafa4fd --- /dev/null +++ b/threads/about_process.py @@ -0,0 +1,25 @@ + +from multiprocessing import Process +import os +import time + + +def run(): + while True: + print(f'current process id: {os.getpid()}') + print(f'parent process id of current process {os.getpid()}: {os.getppid()}') + time.sleep(2) + + +def run2(): + while True: + print(f'current process id: {os.getpid()}') + print(f'parent process id of current process {os.getpid()}: {os.getppid()}') + time.sleep(2) + + +if __name__ == '__main__': + p1 = Process(target=run) + p1.start() + p2 = Process(target=run2) + p2.start() -- cgit v1.2.3