summaryrefslogtreecommitdiff
path: root/threads/about_process.py
diff options
context:
space:
mode:
authorchzhang <zch921005@126.com>2022-12-01 07:22:27 +0800
committerchzhang <zch921005@126.com>2022-12-01 07:22:27 +0800
commit8f4e69ad9557555c1869662114aa9b1909889d6e (patch)
treecaac1132782c5d52092f35bdabd27d65347124a4 /threads/about_process.py
parent665b29a7e9cbc1350f31bf038a3edb3f74466cbe (diff)
multiprocess
Diffstat (limited to 'threads/about_process.py')
-rw-r--r--threads/about_process.py25
1 files changed, 25 insertions, 0 deletions
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()