Can python be used to develop an operating system considering it is a high level language

Operating Systems

12/6/2019 12:15:25 PM

Da Ven

11 Answers

New Answer


Python which is fully interpreted and JIT compiled CANNOT be used to write an Operating system. An operating system manages the hardware resources of the computer and it needs to run directly on top of the hardware without anything in-between. This is called running bare metal. For a running bare metal to happen, operating system must be in binary form so the hardware will understand.. C/C++ are compiled and their codes are converted to binary (so they run bare metal) can be used for an Operating system. though some python's code are compiled but not into binary..the extension is .pyc which is an intermediate but still, it does not run bare metal


I don't know if it can be done, but I think it probably shouldn't. Usually you want your operating system to spare as many resources as possible and run efficiently - because you don't want it to be in the way, when you're using your computer for whatever you're using it. With applications, you can decide whether they should run quickly, be memory-efficient or whatever on a case-by-case basis. Like when you're programming stuff that's not so hardware-challenging, you might go with Python, because writing is quick and simple. But when you need to do crazy processing, like in a 3d game or something, you'd choose a language that makes for quicker code. With an OS, you don't really have that choice - because it will always be running in the background, whatever you play on top of it. So it should probably be quick, small and rather invisible. I'd like to hear what more knowledgeable people say though.


When developing an operating system you're required to have direct access to certain memory regions and communicate with hardware. Python, being a high level language, cannot do these tasks. In the early stages you don't even have the functionality in place to support its allocation and garbage collection. You don't even have support for global variables in C yet. Assembly and C are the go-to languages. Assembly is used to switch the processor from real mode ( a 16 bit compatibility mode ) into protected mode and load in the kernel.


Yes it's possible


And what if you make a python interpreter run in background. I mean, what if the python interpreter is THE main part of the system? You can write some c / asm functions for basic I/O and running task and make python interpreter run all the apps. Then you have : - kernel + routines wrote in c / asm - the python interpreter with all that functions linked, so that it can be called in python - the applicative part (all written in python)


Do you know that the fastest operating systems even use fortran instead of c to just increase the speed a little bit. Fortran is I think at least 5 times harder to code than c and it's syntax is barely close to assembly. On making a operating system all that matters is the speed. Which is opposite of python.


Possibility is low but yea sure it can be


Théophile i don't know about that but i can figure out some problems that would occur if anyone tries that.. It definately won't support networking, no graphics and the OS won't be able to do simple things like threading and memory management. If at all, your method is possible .


Mirielle🐶 [Inactive] it could support networking and graphics. You can create c / asm basic functions for networking, for example, then link them to Python functions. The python interpreter will just be an abstract level. Then, in that os, you can't create native apps in compiled langages, because all apps run with the Python interpreter. But you can still create low-level program in Python by calling the right low-level functions. Thus, you can even create a graphical interface in python, or a filesystem! About threads, why not creating a specific new Python interpreter that can run threads better? Definitely possible.


{ __ƒαянαn__ } I know that. I never said that it has to be fast. It only has to be fast enough, so that you can't see that it is written in python. That can work perfectly on recent processors. I never said I wanted to build an os in python, and if I've to build an os later, I'll never use python (asm and c instead, of course!). I just wanted to let you think about the possibility of writing an os in python.


Théophile Oh... I was just giving you an example. But as python is a platform independent programming language, I think maybe it's possible to make an os with it. But again it will must need a backup of c.