1. Process PID, how to get our process number in the program to see the current process
#-*-Coding:utf-8-*-from multiprocessing import processimport osimport timedef run_proc (): "" "The code to be executed by the child process" " Print (' Sub-process running, pid=%d ... '% os.getpid ()) # Os.getpid Gets the process number of the current process print (' child process will end ... ') if __name__ = = ' __main__ ': print (' parent process pid:%d '% os.getpid ()) # Os.getpid Gets the process number of the current process p = processes (Target=run_proc) P.start ()
The syntax structure of the 2.process is as follows:
Process ([group [, Target [, name [, args [, Kwargs]]]) target: If a reference to a function is passed, the child process can execute the code here, args: parameters passed to the function specified by target, Pass Kwargs as a tuple: pass a named argument to the function specified by target name: sets a name for the process, and does not set the group: Specifies the process group, in most cases, the usual method of using an instance object that is not created by processes: Start () : Start child Process instance (Create child process) is_alive (): Determines whether the process subprocess is still alive join ([timeout]): Whether to wait for the child process to finish executing, or how many seconds to wait terminate (): Regardless of whether the task is completed, Immediately terminates the common properties of the instance object created by the subprocess process: name: The alias of the current process, which defaults to an integer pid that increments from 1 process-n,n: PID of the current process (process number)
Multi-tasking-pid of the process