5.1.3 Network Programming Advanced---View process ID and parent process ID

Source: Internet
Author: User

Get this process id:os.getpid ()

Get parent Process Id:os.getppid ()

 fromMultiprocessingImportProcessImport TimeImportOSclassMyprocess (Process):#inherit the Process class    def __init__(self, name): Super ().__init__() Self.name=namedefRun (self):#You must override the Run method        Print('%s is running; the parent process ID is:%s'%(Os.getpid (), Os.getppid ())) Time.sleep (3)        Print('%s is ending; the parent process ID is:%s'%(Os.getpid (), Os.getppid ()))if __name__=='__main__': P= Myprocess ('XXX') P.start ()#start automatically binds to the Run method    Print('The main process ID is:%s; the parent process ID of the main process is:%s'% (Os.getpid (), Os.getppid ()))#The parent process of the main process is pycharm or the process that executes the script#Output Result:#The main process ID is: 771; the parent process ID of the main process is: 540#772 is running; the parent process ID is: 771#772 is ending; the parent process ID is: 771

5.1.3 Network Programming Advanced---View process ID and parent process ID

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.