Can a program run without an operating system?

guide Today's programmers are used to the operating system, but have you ever thought that if there is no operating system, can we make the program run? It is not easy to write a program that can run directly on the computer. Think about this How to run a program that does not depend on the operating system?

Let me talk about the answer first, of course it is possible, and it must be possible. You can think from this perspective, the operating system itself is a program, and the operation of this program does not depend on any other "operating system". Note that this is not a nesting doll. In fact, in the early days of computer history, or in ancient times, there was no such thing as an operating system on a computer. Programs in this period were indeed written and run without an operating system.

startup is a problem

The first question we face is: there is no program on the computer at this time, how do you start the computer? In other words, what should the CPU do after powering on? Aha, I didn’t expect it, the first question is not Easy to solve, if you want the computer to run your program, you must at least start the computer.

The so-called computer startup is nothing more than allowing the CPU to start executing a piece of initialization code after powering on, paving the way for your real program to run. This large piece of code is the so-called kernel, kernel. In fact, you can let the computer execute any code after powering on. , that is to implement your own kernel, of course, you can also run your program directly without such a kernel. For the startup of the computer, you can refer to this article "How does the operating system start?" But there will still be problems .

runtime issues

The first thing to face is the memory problem. Where will your program be loaded into the memory? Obviously this involves memory management issues. The second problem is that you have no way to fully utilize the computer. Think about it, in this case, you can start to execute a brand new program only when you start it up. If you want to execute the second program, you need to shut down, flash the new program in the storage device and then turn it on again. Is this right? maddening. This is not the end, if your program has bugs, then I'm sorry, you may need to restart the computer, can you imagine restarting the computer if there is a problem with the program? Want to run a text editing program and run a music program at the same time? No, if you want to realize it, write a multi-task (Multitask) management system yourself. You must at least manage the running programs. Think about whether you must use the abstraction of process. I still think these concepts are useless ?

Even if you have a multi-tasking system, if one program has a problem and wipes out the memory of another program, is this killing two birds with one stone? If a bug causes two programs to crash, do you have to have a process isolation mechanism? In addition, if you If the program needs to use I/O devices, it will be even more sour. How do you control these devices without drivers, how to use the mouse, keyboard and monitor? Does your program need to link a lot of drivers? Think about it, is it already a headache? . And you have to efficiently use computer resources. When you get all this done, you will find that you have actually written an operating system. Do you still think the operating system is useless? The operating system takes care of all the dirty work, and programmers only need to focus on writing bugs. Having said so many disadvantages, there is still an interesting advantage of not having an operating system, that is, you can be in charge.

Programmers are also dictators

Interestingly speaking, although you can spend thousands of dollars to buy a computer, there is almost no way for you (programmer) to bypass the operating system to read and write your memory at will, and let the CPU execute any instructions, because your Windows/ Linux /MacOS will kill you directly.

The interesting thing is that the computer hardware and the operating system you bought with your own money are theoretically personal property, but the operating system you bought with money is not under your control (except for the gods), and instead prohibits you Doing this and that is like buying a cow, but the cow is out of control, and you can do whatever you want. If you really bought such a cow, I believe you can't bear it, but you paid a lot of money to buy it. The computers and smartphones that come here are not under your control at all, and people don't feel much about it. They think it's normal, and it's magical enough to think about it. Far away, on the early computers, ordinary programmers (applications) could completely control the computer, which can be said to be in power. In fact, on modern computer systems, you can also write programs without the support of the operating system. This is the so-called Bare-Metal Programming, embedded students should be familiar with this.

Well, this is the end of the topic about the operating system and program running. In short, the operating system is not a necessary component for the computer to execute the program. Without the operating system, we can still make the program run. For more Linux information, please check: https://www.linuxprobe.com

Guess you like

Origin blog.csdn.net/llawliet0001/article/details/124363718
Recommended