Create process and pythoncreate process for python System Programming

Source: Internet
Author: User

Create process and pythoncreate process for python System Programming
I. forking process

The process generated by fork has the following features:

  • Is a process clone.
  • The created process exists independently of the parent process.
  • The thread is copied and executed when fork () is called.
    • Returns 0 in the Child thread.
    • Returns the pid of the subthread in the parent thread.
    • The PID of the sub-thread is different from that of the parent thread.
Ii. Sample Code
#! /Usr/bin/env pythonimport osdef child_process (): print "I am the child process and my PID is: % 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 () if childId = 0: # child_process () else: # print "inside the parent process" print "my child's pid is: % d "% childId while True: passparent_process ()

After the sub-thread ends, the parent thread is still running and has not been released.

3. New Production threads
  • OS .exe c * series Functions
    • OS .exe cl
    • OS .exe cle
    • OS .exe cvp
  • Child process overwrite parent process

It can be found that the created process overwrites the parent process. When the child process ends, the parent process also ends.

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.