Python- operating system, the concept of process

operating system

Multi-channel operating system

Presented the first plurality of programs can be simultaneously calculated in a computer

  • 1. encountered IO let the cpu

  • 2. cpu give other programs so that other programs can use cpu

  • 3.cpu let the matter take up time

  • 4. The two program switching back and forth on a cpu, not mess

    • Each program has a separate memory space

    • Each program record in the current state before and after the switching will

calculating and computing cpu not (IO) operations

IO operation is not accounted for cpu

IO operation (operation network file operations): input and output (relative memory)

  • Obstruction: sleep / input / recv / accept / recvfrom / cpu is not required to participate in

  • The read file: the first reading operation of the disk opposite to the bar codes 90w

input: data (from disk) to the memory input

read/load/input/recv/recvfrom/accept/connect/close

output: output data from memory

write/dump/print/send/sendto/accept/connect/close

IO operations are essentially all file operations

input/print

input is written to the file, and the contents of the input file is loaded into memory by reading the

print is written directly to a file, and then look through the documents presented to the user

Interactive method of socket: all file operations

send a file is written to the cache

recv is read from the cache file

That is at least as far as the operation of the IO is a cpu is the execution time of 0.009s = 90w bar code python

cpu calculated only read into the data memory, the other is not read into memory is not calculated

Round-robin algorithm - sharing operating system

  • 1. The time slice to just let the cpu

  • 2.cpu let out it takes time

  • 3. reduced efficiency, to provide user experience

Mononuclear 1cpu can only run one program

The concept of process

Procedures and processes (minimal computer resource allocation units)

Running program is the process

Data between a process and the process is isolated

Thread (the smallest unit of a computer operating system that can be scheduled)

Each location to which the program execution is recorded

There is one thread in the process responsible for the implementation of specific programs

Process is managed by the operating system

Scheduling process (operating system complete):

Scheduled by the operating system, each process has at least one thread

Short operating priority algorithm

First come first serve algorithm

Round-robin algorithm

Multilevel feedback algorithm

Start the process of destruction

Start the process: 1 interaction (double-click) 2. Start another 3 at startup in a process

The program is responsible for starting a process is called a parent process

The process started is a child process

Destruction: the interaction is killed by another process (at the end of the parent process child process) wrong end of the process

Parent and child

The parent process child process open

The parent process will also be responsible for the end of child processes for resource recovery

The process of the above mentioned id processid pid

On the same machine the same time there can be no duplicate process id

The process id can not set the operating system is randomly assigned

With the process id multiple runs a program may be assigned multiple times each time is different

Three-state map process

Ready ready to run run blocking block

import os
import time
print(os.getpid())
print(os.getppid()) # parent process id
time.sleep(100)

Module mutilprocessing Module: Built-in module

multiple diversification

processing process

Import os 
Import Time
from multiprocessing Import Process
DEF FUNC (): "" "   FUNC executed in the process   : return:   " "" Print ( 'child process:', os. getpid (), os. getppid ()) Time. SLEEP ( . 3) IF the __name__ == 'main': P = process ( target = FUNC) P. Start () Print ( 'primary process:', . OS getpid ()) to the child process parameter passing DEF foo ( A): "" "   foo executed in the process   : return:   """
   



   
   

   
   
   
   


   



   print('子进程:', a)
   time.sleep(3)
if __name__ == '__main__':
   p = Process(target=func, args=(1,))
   p.start()

Parallel: a plurality of programs are simultaneously performed cpu

Concurrent: run multiple programs at the same time looks

Synchronous: A program execution over again to call another and have to wait for the program is finished in the procedure call

Asynchronous: A program execution over the call to another but do not wait for the completion of this task will continue

Blocking: cpu does not work

Non-blocking: cpu work

Guess you like

Origin www.cnblogs.com/womenzt/p/12426531.html