build a Myprocess (Process) class
Internal definition encapsulates the function ppid:return (os.getppid ())
Myprocess create object p1
two questions:
1, see figure which process does the result of 1p1.ppid refer to? Why not 4740?
22
_parent_pid
import time,os
from multiprocessing import Process
class Myprocess(Process):
def __init__(self,name):
super(Myprocess,self).__init__()
self.name = name
def run(self):
print(":\033[1;32;40m%s\033[0m :\033[1;31;40m%s\033[0m" %(os.getpid(),os.getppid()))
print("3")
time.sleep(3)
@property
def ppid(self):
return (os.getppid())
if __name__ == "__main__":
p1 = Myprocess("")
p1.start()
print("%spid:\033[1;32;40m%s\033[0m" % (p1.name,p1.pid))
print("%sppid:\033[1;31;40m%s\033[0m" % (p1.name,p1.ppid))
print(":",os.getpid())