Python operations related to the operating system, threads, and processes

Source: Internet
Author: User

When it comes to operating systems, it is unavoidable to use the OS module, and sometimes the Sys module.

Process actions

The Os.system () function can start a process and return a status code after execution.

Os.fork () Copy a process, if it is a child process return 0, if the parent process returns the PID of the child process, when using this function, it is recommended that you learn the knowledge of Linux programming.
Os.popen creates a process in a pipeline.
OS.SPAWNL can also create processes, and can specify environment variables.

Os.kill (PID, SIG) closes a process, PID is the process number, and the sig is the signal. Used with fork, for example, you just created a sub-process with fork, its PID is 11990, then call
Os.kill (11990, signal. Ctrl_break_event)
The process was killed in the form of CTRL + C.

There is also a module multiprocessing, which encapsulates many of the operations that create processes and interprocess communication, allowing you to perform multicore power.

File operations

For more information on file operations see http://www.cnblogs.com/xinchrome/p/5011304.html

Multithreading Threading & Thread

Multi-process multiprocessing

Thread concurrency control lock semaphore

Process Communication Signal

Python operations related to the operating system, threads, and processes

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.