Operating System Development
The request for the application of static hardware resources become the order of
the first generation: vacuum tubes, plug-in version, there is no operating system concepts, can only be a one time use (waste of resources)
The second generation: transistors and batch processing technology, saving machine , the people involved need to control
the third generation: an integrated circuit chip, multi-channel programming
modern computer:
the general multi-core, each core has a multi-channel technology
when a program is run blocking, IO will end rescheduled, the largest number of nuclear
scheduling cpu any one of an operating system scheduling algorithm decides
IO: not only the input-output device, the hard disk memory to read the code, stored in the hard disk memory, network IO
Serial: complete a full account of the execution done in the implementation of a
concurrent: it appears to be running simultaneously (+ switching state of preservation)
Parallel: truly run, only to achieve a parallel multi-core
Multi-channel technology:
Spatial multiplexing: a public memory, each process has its own separate memory space, without disturbing each other, the level of physical isolation
(to pave the way for time multiplexing)
time multiplexing: a public the CPU,
the CPU switch : IO when occupying too long when switching
Process Overview
Process: ongoing task
Create a process: the system initialization; a process has been started during the run child process; user interaction request, the process of creating a new
process of three basic states: running, blocking, ready
-ready: In addition to processor resources, others are ready, as long as assigned processor can execute a process
to run: the process takes processor resources, this process is less than the number of states equal to the number of processors, usually idle computers to perform the process of
blocking: the lack of certain conditions before the conditions are met in a timely manner allocated processor resources to the process, can not run
Two ways to open a child process
method one:
from multiprocessing import Process
# 导入模块,可以开启子进程
import time
def task(x):
print(f'{x},start')
time.sleep(2)
print(f'{x},end')
if __name__ == '__main__':
p = Process(target=task,args=('lqz',)) # 目标
p2 = Process(target=task,args=('lhf',))
p.start()
p2.start() # 告诉操作系统开启进程,告诉完就执行完了,操作系统什么时候开子进程我们不能控制
time.sleep(5)
print('主进程')
Second way:
from multiprocessing import Process
import time
class Test(Process):
def __init__(self,sex):
self.sex = sex
def run(self):
print(f'{self.sex}.start')
time.sleep(5)
print(f'{self.sex}.end')
if __name__ == '__main__':
p = Test()
p.start()
print('主进程')
Zombie process, orphaned
Zombie process: pid warranty status information such as the end of the child process (not really dead)
Orphan process: parent dies in his death