python3 process name and the pid

# Coding: UTF. 8- 
Import OS
 from multiprocessing Import Process 


class MyProcess (Process):
     DEF  the __init__ (Self, Nam): 
        . Super () the __init__ () 
        self.nam = Nam   # because the parent class has a name attribute, if there or use the property name, overrides the value of the parent class name, and I used nam 


    DEF RUN (Self):
         Print ( " . child process start " )
         Print ( " child process number os.getpid (): " , os.getpid ( ))
         Print ( " child process name name: ", Self.name)
         Print ( " child process end. " ) 


IF  __name__ == ' __main__ ' : 
    the p- = MyProcess ( " Lily " ) 
    p.start () 
    Print ( " p.name: " , p.name)
     Print ( " p.pid: " , p.pid) the results:
 


# p.name: MyProcess-1 # p.pid: 6388 # child process begins. # child process number os.getpid (): 6388 # child process name name: 1-MyProcess # child process ends.

There are not found, the process of obtaining numbers in two ways: p.pid and os.getpid ()

Guess you like

Origin www.cnblogs.com/lilyxiaoyy/p/10966995.html