Multi-tasking-pid of the process

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.