Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Once upon a time, there was a magical machine

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > IT Information >

Share

Shulou(Shulou.com)11/24 Report--

This article comes from the official account of Wechat: programming Technology Universe (ID:xuanyuancoding), author: Xuanyuan Wind O

Once upon a time, there was a machine that was so big that it could add thousands of times per second. When it became famous, man gave it a name: computer.

In addition to addition, it can also calculate square, cubic, sine and cosine, which is much faster than the human brain.

Many programs come here and want to run on it and experience the feeling of flying.

"come on, line up, one by one," the computer administrator said.

All the programs lined up one by one, waiting for the administrator to subpoena.

After executing one, the administrator will take it out and replace it with the next one to start execution.

Over time, programs complain: wait in line for ten minutes and execute for three seconds. The human administrator is too slow, time is spent in the queue, can you let the computer automatically complete the program switch, not manual switch?

The speed of manual operation is much slower than that of the computer, and the man-machine contradiction has become increasingly prominent. Human beings decided to redesign the machine and developed a control program under its command, which can execute the program in batches and switch automatically. There is no need for human intervention, and the efficiency has improved a lot.

More and more programs are being processed by multiple programs, and the queues waiting for execution are getting longer and longer.

Some programs become impatient and ask the control program: "Big Brother, you see that guy in front of you is doing input and output. CPU is free. It's not a waste at 01:30. Isn't it a waste? why don't you call the next one up to execute it?"

The control program frowned and said, "how can you do that? all the data executed by the previous program is in memory, and then put in the program. If you break it, who will be responsible for it? besides, there is only one CPU. What should you do when the previous program is busy with input and output?"

Everyone stopped talking for a moment, and no one could give any advice. they sighed one after another, so they had to give up and go on waiting.

But smart humans have discovered the problem: letting a program monopolize the computer is indeed a waste of resources. When performing input and output, the CPU is empty, and when performing computing operations, the input and output device is idle again, and there is always one idle.

So humans redesigned the computer and developed a new version of the control program, this time allowing multiple programs to enter the computer for execution at the same time.

If program An executes input and output, leave CPU free for another program B to execute, then B executes input and output later, and then assign CPU to A for execution, alternating with each other, so that it will not be wasted!

It wasn't long before time was sliced, and a new problem appeared.

On this day, other programs were waiting in line for the control program to turn over the brand, but there was no subpoena for the left and right. The program was in a hurry, and the control program was questioned, and the control program poured out its grievances: "the guy in front wrote an endless cycle, and life and death can't end!"

Hearing what he said, all the programs were angry.

"how can that be? it's so selfish."

"you have no control over this control program, so what's the use of you?"

"think of something quickly!"

"there's nothing I can do. He doesn't execute input and output, and I can't get control of CPU. There's nothing I can do about it," the control program sighed.

The procedures are full of tongues, and the quarrels are inextricable.

Sensitive human beings once again discovered this problem, made a good study, and developed a technology called "interrupt": it can send an interrupt signal to CPU, and when CPU receives the signal, it has to stop its work and execute the control program to process the interrupt signal, so that the control program has a way to gain control!

In order to enable the control program to gain control in time, humans have created an interrupt source that periodically sends an interrupt signal to the CPU, which is called a clock interrupt.

The upgraded control program began to work again, and many programs came after hearing the wind.

"Big Brother, I heard that you have upgraded again. What have you changed this time? can you fix the procedure of the endless cycle?" One program asked.

"everybody line up and listen up. Now it is divided according to time slices. Each program has only a short period of time at a time. As soon as the time runs out, I have to ask him to come out and let other programs come."

"what if time is up and I haven't finished implementing it?"

"Don't worry, it's all your turn, and you'll have a chance to execute it again in the next round," the control program explained.

"with so many programs, we won't have to wait a long time for the next round."

"this computer has been upgraded from the inside to the outside. despite the fact that it is getting smaller, it is full of large-scale integrated circuits, and its execution speed is much faster than the big guy before. It can perform hundreds of thousands of operations per second ~ you turn around and come back before you feel it."

After listening to the program, there was an uproar, "hundreds of thousands, my darling! this is too fast. Let's experience it."

With that, everyone lined up to board the upgraded computer to run.

Sure enough, the upgraded computer runs fast. With a clock interrupt, the control program can always gain control of the CPU on time, silently controlling the operation of the programs behind it, and many programs do not feel that they have ever stopped.

However, although the speed of the computer has become faster, there are more popular programs, and the functions of these programs are becoming more and more complex.

Gradually, programs are no longer satisfied with the status quo, and new problems begin to emerge.

Some programs are in sleep, some programs are waiting at the same time, wasting time slices in vain, everyone protested to the control program, but the control program said that all programs should be treated equally and fair, but everyone dared not say it face to face, but scolded him for inaction behind his back.

The control program fed back the problem to humans, and the clever engineer began to wonder: it is really wrong for all programs to rotate in one line, and they have to be divided into different states, and only those programs that are ready are qualified to be executed.

Humans have done a number of task states in one breath, creating, getting ready, running, blocking, and terminating

The control program becomes more and more complex. It only needs to be subpoenaed one by one, but now we have to record their status and choose the right program to run, which increases the workload a lot.

I thought that with such a change in priority, everyone would be satisfied, but a few old Youtiao secretly found the control program: "Brother, some of our programs have relatively high real-time requirements, can you give us the entire VIP queue, don't queue with them, and give priority to us?"

The control program turned green and flatly refused.

One of the guys said, "our programs are very important. Can you afford the delay?"

There is no way, the control program can only be fed back to humans again. When the engineer thought about it, it was too hasty for all programs to have the same priority.

The engineer upgraded the control program again, this time, not only divided the task status, but also set different priorities, divided different teams, and let the programs queue up in their respective priority queues, giving priority to the implementation of high-priority programs.

Not only that, if a high-priority program appears, even if the time slice of the low-priority program is not used up, it will be deprived of the opportunity to execute, which engineers call preemption.

However, this change, the control program has all been blinded in the drum, if you know that they have also been divided into three, six or nine classes, estimated to be crazy.

After this round of changes, everyone finally lived a quiet life.

The development of hardware technology in the multi-core era is so fast that one day, human beings excitedly told the control program: now that there are multiple cores in CPU, we can really execute multiple programs at the same time, so we have decided to upgrade you again!

But for the control program, this is not good news, the original one core program scheduling management has made him busy enough, now there are multiple cores, this scheduling management task is more complex. It used to be a queue with multiple priorities, but now each core has to develop a set. It's a big head to think about.

Human beings began to operate on the control program, making it more and more complex and powerful.

Finally, he was given a new name: operating system.

PS: the story belongs to the story. The name operating system does not appear only after multi-core.

In addition, the modern operating system is more complex, state, preemption, priority, dynamic priority, dynamic time slice, affinity and various factors are intertwined, integrated scheduling, there are a variety of scheduling algorithms coexist.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

IT Information

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report