Operating system one

Review of knowledge 
- a computer known as a computer, that is energized brain, invention of the computer is so he can go to work like a human after power
and higher efficiency than the person's work, because uninterrupted 24 hours
- the five components of the computer
- The controller
-operator
-memory
-input device
-output device
-the core of the computer is the CPU (controller + operator = central processor)-the
program wants to be run by the computer, its code must be read by the hard disk memory, CPU fetched and then executed after

today's content
- operating system development history <https://www.cnblogs.com/Dominic-Ji/articles/10929381.html>
- multi-channel technology
- multicore concurrency effect
- concurrent : It looks like running concurrently can be called concurrent
-parallel: in the true sense of simultaneous execution
-ps: parallel must be considered concurrent, single-core computers certainly cannot achieve parallel, but can achieve concurrent
-supplement: we directly assume single-core is a core, work on a man, do not consider the number of cores inside the CPU
- multi-channel technical illustration
- saving multiple programs running total elapsed time
- focus on multi-channel technology knowledge
- space Multiplexed on the multiplexing and time
- multiplexing on the space
- a common set of computer hardware more programs
- multiplexed on time
- eat and play games
-Switching + saving state
Switching the CPU is divided into two cases
1. When a program encounters IO operation, the operating system will deprive the program of the CPU execution authority
Function: improve the CPU utilization, and does not affect the execution efficiency of the program
2. When a program occupies the CPU for a long time, the operation attraction will also deprive the program of the CPU execution authority.
Drawbacks: reduce the execution efficiency of the program (original time + switching time)

process theory
-the difference between program and process
-the program The code lying on the hard disk is "dead"
-the process indicates the process being executed and is "live"
-process scheduling
-first come first service scheduling algorithm-"beneficial for long jobs, not for short jobs
-Short job priority scheduling algorithm-"Good for short jobs, not good for long jobs
-Time slice rotation method + multi-level feedback queue

process running three state diagrams
Two important concepts
-synchronization and mutual exclusion-" describes submit the task way
synchronization: after job submission, returns the result in place of waiting tasks, waiting for the process does nothing (dry, etc.)
demonstrated that procedural level Live
asynchronous: After job submission, no place to wait tasks return results directly to do other things
the task of how to get my report? The return result of the task will be automatically handled by an asynchronous callback mechanism
-blocking and non-blocking-describes the running state of the program
Blocking: blocking state
Non-blocking: ready state, running state
Ideal transition: we should let the code we write always switch between the ready state and the running state.

The most efficient combination of the above concept combinations is the asynchronous and non-blocking

two ways to
start the process . The code starts the process and thread. Code writing is basically the same, you learned how to start a process to learn
how to open a thread

summary: create process is to apply for a piece of memory space code required to run throw into the memory of
a corresponding process in memory is a separate memory space
and more Each process corresponds to multiple independent memory spaces in memory
. Data between processes and processes cannot be directly interacted by default. If you want to interact, you can use third-party tool modules.

#Two ways to start the process
from multiprocessing import Process
import time

def task (name):
print ("% s is running"% name)
time.sleep (3)
print ("% s is over"% name)

if __name__ = = '__main__': #Create
an object
p = Process (target = task, args = ("jason",)) #Start
process
p.start () # Tell the operating system to help you create a process asynchronous
print ("main process" )
"""
第二种方式 类的继承
from multiprocessing import Process
import time

class MyProcess(Process):
def run(self):
print("hello my dear")
time.sleep(1)
print("looking forward")

if __name__ == '__main__':
p=MyProcess()
p.start()
print("主进程")

"""
#join Method join is to let the main process wait for the subprocess code to finish running, and then continue to run. 
# Does not affect the execution of other subprocesses
""
from multiprocessing import Process
import time

def task (name, n):
print ("% s is running "% name)
time.sleep (n)
print ("% s is over "% name)

if __name__ == '__main__':

start_time = time.time ()
p_list = []
for i in range (1,4 ):
p = Process (target = task, args = ("child process% s"% i, i))
p.start ()
p_list.append (p)
for p in p_list:
p.join ()
print ("main Process ", time.time ()-start_time)

" ""
"" "The 
data between processes is isolated
from multiprocessing import Process
money = 100
def task ():
global money
money = 666
print (" subprocess ", money)

if __name__ == '__main__':
p = Process (target = task )
p.start ()
p.join ()
print (money)
"" "

Guess you like

Origin www.cnblogs.com/mayrain/p/12756181.html