Creation process of Python system programming

Source: Internet
Author: User

I. Forking process

The process produced by fork has the following characteristics:

    • is a clone of a process.
    • The created process exists independently of the parent process.
    • The thread is copied to execute at the call fork ().
      • Returns 0 in the child thread.
      • Returns the PID of the child thread in the parent thread
      • The PID of a child thread differs from the parent thread.
Second, code example
#!/usr/bin/env pythonImportOs def child_process():    Print "I am the child process and my PID are:%d"% Os.getpid ()Print "teh child is exiting." def parent_process():    Print "I am the parent process whit PID:%d"% os.getpid () childID = Os.fork ()ifchildID = =0:#在子进程中Child_process ()Else:#在父进程中        Print "Inside the parent process"        Print "My child's PID is:%d"% childID while True:PassParent_process ()

When the child thread ends, the parent thread is still running and is not rolled out.

Third, mass production of new threads
    • Os.exec* Series functions
      • Os.execl
      • Os.execle
      • Os.execvp
    • Child process Overrides parent process

You can see that a process created in this way overrides the parent process, and the parent process ends when the child process ends.

Creation process of Python system programming

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.