Pid problem of parent process and child process?

< H2 > question: < / H2 >

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?
p1.ppid4740

22
_parent_pid
_parent_pid

< H2 > Source code: < / H2 >
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())
Mar.05,2021

ppid is another id, of pycharm


1, the result of _ parent_pid, 3400, refers to the parent process of the current main process, that is, pycharm
2. During the running of the main process, all the definitions except run, in the MYprocess are completed in the main process 4740. Only after p1.start () applies for a successful system call, after the main program calls the subroutine run (), the subroutine 9812 is obtained.
that is, if you want to get the parent process pid, in the process object p1, you can't use os.getppdid (), but os.getpid ()

    @property
    def ppid(self):
        return os.getpid()
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e9ab58-68f6c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e9ab58-68f6c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?