Operating system History manual operation (no operating system)
1946 the first computer was born-the mid 1950s, the operating system has not yet appeared, the computer work by manual operation mode.
Manual operation
The programmer will load the perforated paper tape (or card) corresponding to the program and data into the input machine, then start the input machine to enter the program and data into the computer memory, and then start the program through the console switch for the data run, the calculation is finished, the printer output calculation results; After the user takes the results and unloads Glimpse the next user on the machine.
Manual mode of Operation two features:
(1) User exclusive full machine. There is no wait for resources to be consumed by other users, but the utilization of resources is low.
(2) The CPU waits for manual operation. The utilization of the CPU is not sufficient.
? In the late the 1950s, there was a contradiction between human and machine: The slow speed of manual operation and the high speed of the computer formed a sharp contradiction, the manual operation method has seriously impaired the utilization of the system resources (to reduce the utilization of resources to a few percent, or even lower), can not tolerate. The only solution: to get rid of the manual operation of people, to achieve automatic transition of the job. In this way, batch processing occurs.
Batch processing System
Batch system: A system software loaded on a computer that, under its control, can automatically and in batches process the jobs of one or more users (the job includes programs, data, and commands).
Online Batch processing system
The first occurrence is the online batch processing system, that is, the input/output of the job is handled by the CPU.
Add a storage device between the host and the input machine-tape, under the control of the monitoring program running on the host computer can be automatically completed: batch of the input machine to read the user's work into the tape, in turn, the user's work on the tape read into the host memory and execute and output the results to the output machine. After the completion of the last batch of work, the supervision program from the input machine input another batch of jobs, saved on tape, and follow the above steps to repeat processing.
The supervision procedure handles the work continuously, thus realizes the automatic transfer of the job to the job, reduces the work settling time and the manual operation time, overcomes the human-machine contradiction effectively, and improves the utilization of the computer.
However, at the job input and output, the host's high-speed CPU is still idle, waiting for the slow input/output device to complete its work: The host is in a "busy" state.
Offline Batch processing System
In order to overcome and alleviate the contradiction between high-speed host and slow-speed peripherals, improve CPU utilization, and introduce the Offline batch processing system, i.e. I/O out-of-host control.
A notable feature of this approach is the addition of a satellite machine that is not directly connected to the host and is specifically designed to deal with input/output devices.
Its functions are:
(1) Read the user's job from the input machine and put it on the input tape.
(2) Read the execution result from the output tape and pass it to the output machine.
In this way, the host is not directly with the slow input/output devices, but with the relatively fast speed of the tape drive relationship, effectively alleviate the contradiction between the host and equipment. The host and the satellite machine can work in parallel, the two are clear division of labor, can give full play to the host's high-speed computing ability.
Offline batch processing system: the 1960s is widely used, it greatly alleviates the contradiction between the human machine and the host and peripherals. ibm-7090/7094: The supervised procedure is the offline batch processing system, which is the prototype of the modern operating system.
Insufficient: Each time a single job is stored in the host memory, the high-speed CPU waits for low-speed I/O completion status whenever it is running, causing the CPU to be idle.
In order to improve CPU utilization, the multi-channel program system is introduced.
Multi-Channel program system
Multi-Channel program design Technology
The so-called multi-Channel program design technique means that multiple programs are allowed to enter memory and run simultaneously. That is, putting multiple programs into memory and allowing them to run alternately on the CPU, sharing the various hardware and software resources in the system. When a program pauses to run due to an I/O request, the CPU immediately goes to run another program.
The operation process of the single-channel program:
In a program calculation, I/O idle, a program I/O operation, the CPU idle (b program is the same); Must a work is completed, B to enter the memory to start work, the two are serial, complete the total time required =t1+t2.
The process of running a multi-channel program:
The A and B programs are stored in memory at the same time, they can be interleaved and alternately run on the CPU under the control of the system: when a program abandons the CPU due to request I/O operation, the B program can occupy the CPU, so that the CPU is no longer idle, and I/O operation is not idle, obviously , CPU and I/O devices are in a "busy" state, greatly improve the utilization of resources, and thus improve the efficiency of the system, A, b all the time required to complete <<t1+t2.
The multi-channel program design Technology not only makes the CPU fully utilized, but also improves the utilization of I/O devices and memory, which improves the resource utilization and system throughput of the whole system (the number of processing jobs (Programs) per time), and finally improves the efficiency of the whole system.
The characteristics of multi-channel program operation in a single processor system:
(1) Multi-channel: In the memory of the computer to store several independent programs;
(2) macro-parallel: At the same time into the system of several procedures are in operation, that is, they have started their own operation, but have not finished running;
(3) Micro-serial: In fact, the various procedures with the CPU rotation, and alternately run.
The advent of the multi-channel program system indicates that the operating system is maturing gradually, and has appeared the functions of job scheduling management, processor management, memory management, external equipment management, file system management and so on.
Multi-channel batch processing system
The mid 1960s, in the aforementioned batch processing system, the introduction of multi-channel program design technology to form a multi-channel batch processing system (short: Batch processing System).
It has two features:
(1) Multi-channel: The system can accommodate multiple jobs at the same time. These jobs are placed in the external memory, a backup queue, the system according to a certain scheduling principle to select one or more jobs from the backup queue every time into memory run, run job end, exit run and backup job into the operation are automatically implemented by the system, in order to form an automatic transfer in the system, continuous job flow.
(2) Batch: During the system operation, the user is not allowed to interact with their job, that is: Once the job enters the system, the user can not directly interfere with the operation of their operations.
The goal of the batch processing system is to improve system resource utilization and system throughput, as well as the automation of the job flow.
One of the important drawbacks of batch processing system is that it does not provide human-computer interaction ability, which brings inconvenience to users.
Although the user exclusive full-machine resources, and direct control program run, you can always know the operation of the program. However, this mode of work is extremely inefficient due to the monopoly of the whole machine.
A new goal: not only to ensure the efficiency of the computer, but also convenient for users to use the computer. In the the mid 1960s, the development of computer and software technology made this pursuit possible.
Ctss
Because of the increasing CPU speed and the use of time-sharing technology, a computer can connect multiple user terminals simultaneously, and each user can use the computer on their own terminal, as if their own machine.
Time-sharing technology: The operating time of the processor into a very short time slices, in turn, the processor allocated to the use of online operations.
If a job cannot complete its calculations within the time slice allocated to it, the job is temporarily interrupted, the processor is given another job, and the next round is resumed. Because the computer is fast and the job runs very quickly, the impression to each user is that it seems that he has an exclusive computer. And each user can send a variety of operation control commands to the system through their terminal, and complete the operation of the work under the condition of full human-computer interaction.
A computer system with the above characteristics is called a time-sharing system, which allows multiple users to use the computer online simultaneously.
Characteristics:
(1) Multiplexing. Several users use a single computer at the same time. Microscopic view is that each user takes turns to use the computer, macro view is the user work in parallel.
(2) Interactivity. The user can further make a new request to the system based on the response of the system to the request. This can make the user and the system of Man-machine dialogue work way, obviously different from batch processing system, therefore, time-sharing system is also called interactive system.
(3) Independence. Users can operate independently of each other and interfere with each other. The system guarantees the integrity of the operation of each user program and does not confuse or destroy each other.
(4) timeliness. The system can respond to the user's input in a timely manner. One of the main indicators of CTSS performance is response time, which refers to the time it takes to issue commands from the terminal to the system to answer.
The main goal of the time-sharing system is to respond to the user in a timely manner, that is, the user is not waiting for the processing time of each command too long.
Time-sharing system can accept dozens of or even hundreds of users, because of limited memory space, often using a swap (also known as Exchange) method of storage. Will not "turn" of the job into the disk, once the "turn", and then put it into memory, and the time slice, and then put the job back to disk (commonly known as "roll in", "roll Out" method), so that the same storage area in turn for multiple users service.
Multi-user Time-sharing system is one of the most commonly used operating systems in today's computer operation system.
Real-time Systems
Although multi-channel batch processing system and time-sharing system can obtain more satisfactory resource utilization and system response times, they can not meet the needs of two applications in real-time control and real-time information processing. Thus, a real-time system is created, in which the system responds to random external events in a timely manner and completes the processing of the event within a strict time frame.
Real-time systems are often used as a control device in a particular application.
Real-time systems can be divided into two categories:
(1) Real-time control system. When used in the automatic control of aircraft flight and missile launch, the computer can process the measured data of the measurement system as soon as possible, control the aircraft or missiles in time, or provide the information to the decision-makers through the display terminal. When used in steel rolling, petrochemical and other industrial production process control, also requires the computer to process the data sent by various sensors in a timely manner, and then control the corresponding executing agencies.
(2) Real-time information processing system. When used to book air tickets, inquiries about flights, routes, fares and other matters, or when used in banking systems, information retrieval system, the computer can be sent to the terminal equipment to the service request in time to correctly answer. This type of response to timeliness is slightly weaker than in the first class.
Key features of the real-time operating system:
(1) Timely response. The process of receiving, analyzing and sending each information must be completed within strict time limits.
(2) High reliability. Need to take redundant measures, dual-machine system before and after work, but also include the necessary confidentiality measures.
Process and thread what is a process?
An executing instance of a program is called a process.
Each process provides the resources needed to execute a program. A process has a virtual address space, executable code, open handles to system objects, a security context, a unique proce SS identifier, environment variables, a priority class, minimum and maximum working set sizes, and at least one thread of Execution. Each process was started with a single thread, often called the primary thread, but can create additional threads from any of its threads.
The program does not run alone, and the program is assigned resources to run only if it is loaded into memory, and this execution is called a process. The difference between a program and a process is that a program is a set of instructions, which is a static descriptive text of the process, and a process is an execution activity of a program, which belongs to the dynamic concept.
In multi-channel programming, we allow multiple programs to be loaded into memory at the same time, which can be implemented concurrently under the dispatch of the operating system. This is the design that greatly improves the CPU utilization. The advent of the process makes it possible for each user to feel the CPU alone, so the process is proposed for multi-channel programming on the CPU.
Why do threads still have a process?
The process has many advantages, it provides multi-channel programming, let us feel each of us have their own CPU and other resources, can improve the utilization of the computer. Many people do not understand, since the process is so good, why do threads? In fact, careful observation will find that the process is still a lot of defects, mainly reflected in two points:
A process can only do one thing at a time, and if you want to do two or more things at once, the process is powerless.
If a process is blocked during execution, such as waiting for input, the entire process hangs, even if some work in the process does not depend on the input data, it cannot be executed.
For example, we use QQ chat, QQ as an independent process if only one thing at the same time, how can he realize at the same moment to be able to monitor the keyboard input, but also can listen to other people send you the message, while still can send someone else's message on the screen? You would say that the operating system is not a tick? But my pro, tick refers to a different process between the time, that is, the operating system to handle your QQ task, and switch to the Word document task, each CPU time slice to your QQ program, your QQ or can only do one thing at the same time.
A bit more straightforward, an operating system like a factory, the factory has a lot of production workshops, different workshops to produce different products, each workshop is equivalent to a process, and your factory is poor, insufficient power, the same time only to a workshop power supply, in order to allow all the workshop can be produced simultaneously, Your factory electrician can only give different workshop time power supply, but your QQ workshop, found that only a working workers, the result is very low production efficiency, in order to solve this problem, should do? Yes, you must have thought of, is to add a few workers, let a few artificial people work in parallel, this every worker, is a thread!
What are threads (thread)?
A thread is the smallest unit that the operating system can perform operations on. It is included in the process and is the actual operating unit of the process. A thread refers to a single sequential control flow in a process in which multiple threads can be concurrently, each thread performing different tasks in parallel
A thread is the smallest unit that the operating system can perform operations on. It is included in the process and is the actual operating unit of the process. A thread refers to a single sequential control flow in a process in which multiple threads can be concurrently, each thread performing different tasks in parallel
A thread is a execution context, which are all the information a CPUs needs to execute a stream of instructions.
Suppose you ' re reading a-book, and you want-to-take a-break right now, but you want-be-able-come back and resume Rea Ding from the exact point where you stopped. One-to-achieve-is-jotting down the page number, line number, and word number. So your execution context for reading a book is these 3 numbers.
If you have a roommate, and she's using the same technique, she can take the book while you ' re not using it, and resume re Ading from where she stopped. Then you can take it back, and resume it from the where you were.
Threads work in the same. A CPU is giving the illusion that it's doing multiple computations at the same time. It does that is spending a bit of time on each computation. It can do this because it has a execution context for each computation. Just like you can share a book with your friend, many tasks can share a CPU.
On a more technical level, an execution context (therefore a thread) consists of the values of the CPU ' s registers.
Last:threads is different from processes. A thread is a context of execution, while a process is a bunch of the resources associated with a computation. A process can has one or many threads.
Clarification:the resources associated with a process include memory pages (all the threads in a process has the same VI EW of the memory), file descriptors (e.g., open sockets), and security credentials (e.g., the ID of the user who started T He process).
What is the difference between a process and a thread?
- Threads share the address space of the process that created it; Processes has their own address space.
- Threads has direct access to the data segment of its process; Processes has their own copy of the data segment of the parent process.
- Threads can directly communicate with other Threads of its process; Processes must use interprocess communication to communicate with sibling processes.
- New threads is easily created; New processes require duplication of the parent process.
- Threads can exercise considerable control over Threads of the same process; Processes can only exercise control over the child processes.
- Changes to the main thread (cancellation, priority change, etc.) may affect the behavior of the other threads of the Proce ss Changes to the parent process does isn't affect child processes.
Python GIL (Global interpreter Lock)
In CPython, the global interpreter lock, or GIL, was a mutex that prevents multiple native threads from executing Python by Tecodes at once. This lock is necessary mainly because CPython ' s memory management are not thread-safe. (However, since the GIL exists, other features has grown to depend on the guarantees that it enforces.)
The core of the above is that, no matter how many threads you start, how many CPUs you have, Python will only allow a single thread to run at the same time when it executes.
Instance
ImportThreadingImport Timedefrun (N): Time.sleep (1) #print (Threading.get_ident ()) Print("Thread", N)Print(Threading.current_thread ())Print(Threading.active_count ()) T= Threading. Thread (target=run,args= (1,)) T.start ()Print('-------------') T2= Threading. Thread (target=run,args= (2,)) T2.start ()Print(Threading.active_count ())
The above code runs the result
1-------------31<thread (Thread-1, started 8088) >2<thread (Thread-2, started 12816) >
After the main thread initiates the child threads, the main thread is the same as the child thread, the main thread ends, and the child threads continue to run.
Instance
Quit when the child thread is finished running
ImportThreadingImport Timedefrun (N): Time.sleep (1) #print (Threading.get_ident ()) Print("Thread", N)Print(Threading.current_thread ())#print An instance of a thread that is currently running forIinchRange (10): T= Threading. Thread (Target=run, args=(i,)) T.start () T.setname ("t-%s"%i)Print(T.getname ())Print(Threading.active_count ())Print(Threading.current_thread ()) Time.sleep (1.5)Print(Threading.active_count ())
The above code runs the result
T-0t-1T-2T-3T-4T-5T-6T-7T-8T-911<_mainthread (Mainthread, started 5328) >Thread 0thread3<thread (t-3, started 11760) ><thread (t-0, started 14116) >Thread4<thread (t-4, started 5500) >Thread1<thread (t-1, started 13904) >Thread2<thread (T-2, started 14068) >Thread5<thread (t-5, started 968) >Thread9<thread (t-9, started 7728) >Thread8<thread (t-8, started 6724) >Thread7<thread (t-7, started 10912) >Thread6<thread (t-6, started 10076) >1
Thread Waits
ImportThreadingImport Timedefrun (N): Time.sleep (1) Print("Thread", N) t_list= [] forIinchRange (10): T= Threading. Thread (Target=run, args=(i,)) T.start () t_list.append (t)#print (t_list) forTinchT_list:t.join ()Print("--main Thread---")
The above code runs the result
Thread 421375869--main Thread---
Daemon Threads
Import Threadingimport timedef run (n): time.sleep (1) Print("thread", N) for in range ( ): = Threading. Thread (Target=run, args=(i,)) T.setdaemon (True) T.start ()print(" --main Thread--- ")
The above code runs the result
--main Thread---
threads, processes