r/AskComputerScience • • Sep 15 '20

Can you create an operating system which will support executable types of multiple kernel of operating system?

Is it possible even in theory to create an operating system which will support executables from different operating systems such as Windows, Ubuntu , MacOS ? If no what are the obstacles and challenges ?

32 Upvotes

17 comments sorted by

31

u/chrisgseaton Sep 15 '20

Any Turing-complete platform can execute code of any other Turing-complete platform, so yes. The only obstacles are it being possibly too slow, possibly using too much memory, or possibly just being a huge amount of work to implement it.

24

u/AmateurHero Sep 15 '20 edited Sep 15 '20

Absolutely. Linux basically does this with Wine. It's a compatibility layer to allow Windows syscalls to operate on Linux (really POSIX if I'm not mistaken).

As another commenter mentioned, this isn't ideal. Running non-native applications on a usually suffers from performance issues, and even though applications like Wine have come a long way, there's no guaranteed way to alleviate all of those bottlenecks.

Edit: I forgot to obviously mention Windows Subsystem for Linux. It may seem like virtualization, but it's another compatibility layer bringing Linux functionality to Windows. Anyone who was unimpressed with the initial version of WSL may want to check out WSL2. Microsoft has made really good improvements to it.

6

u/lead999x Sep 15 '20

Is WSL2 even a compatibility layer anymore if it's using an actual Linux kernel? Granted I think turning it on requires you to run your whole system in a hypervisor, windows itself included.

7

u/Poddster Sep 15 '20

Yep. The current operating systems do a lot of this already :)

Windows uses PE as its executable format. It can still run PE's designed for the win16 API, though I doubt that's answering your question.

But if you install the Windows Subsystem For Linux then you can run ELF executables. It's done in a roundabout way (i.e. via a special subprocess 'ubuntu' terminal), but it's still going through the NT kernel and so process can communicate with each other. The WSL also provides the filesystem framework expected by most Linux programs.

On the Linux side you have things like Wine which can run Windows PE on Linux.

And remember when Mac went from POWERPC to x86? They used Rosetta to live-translate the binaries.

But there's currently no OS which can run, as a general case, a binary meant for every other OS. Heck, you often can't even run a binary meant for Linux Distro X on Linux Distro Y because of the way they're configured differently. (Or: you can, but not without lots of fiddling)

If no what are the obstacles and challenges ?

Time and money, mostly. At the end of the day it's all just software, so it can always be translated into the correct thing. But no one really sees a business need to.

6

u/DrunkHacker Sep 15 '20

8

u/[deleted] Sep 15 '20

Hmm, correct me if i’m wrong, but aren’t virtual machines just running a copy of that OS?

If i’m not mistaken, OP is asking about creating an OS that could run any executable program from any existing OS. For example, an OS that could run EXE, APP, JAVA, etc.

8

u/[deleted] Sep 15 '20

Practically speaking, Virtual Machines are the right implementation. Rather than figuring out how to run non-native executables natively, the host OS would keep Virtual Machines around and proxy execution to them. The host OS can hide the use of virtual Machines to provide the interface OP is wanting.

The alternatives are to build emulators or rebuild the entire OS natively, such as wine. If you're interested in why this is a bad solution, look into the history of wine and how much effort it takes to make it work for individual applications.

3

u/[deleted] Sep 15 '20

Oh I’m not saying that it’s a good idea, I was just trying to clarify that I don’t think Virtual Machines necessarily answer the OP’s question. It seems they’re asking if it’s possible to create some super OS that can run any non-native executable. But yeah totally agree, I don’t think it’s worth the effort.

4

u/[deleted] Sep 15 '20

The implementation may not be what you or OP had in mind, but using VMs does meet the requirements.

4

u/Ghost_out_of_Box Sep 15 '20

VMs are great and can be used to achieve great tasks but that means two OS using a lot of system resources one over another for just simple tasks . I wonder if there is any way to suspend unnecessary processes and threads of both the OS to reduce the load machine and to make direct system call from the VM OS.

3

u/[deleted] Sep 15 '20

for just simple tasks

I mean, you're wanting to run arbitrary binaries on a single OS. This entire problem is outside the realm of simple tasks. Compiled executables are tightly coupled to OS and architecture for a reason. Let's say >cat "Hello World" where you're running cat compiled for linux/amd64 on windows/amd64, is not simple. It is solved, and probably could be reimplemented fairly easily (I'm no expert on elf vs exe), but it isn't trivial, and more importantly doesn't begin to scratch the surface of complexity this problem opens up. Try that "Hello World" again in a windowed environment and you're looking at months just to get the basics working.

1

u/[deleted] Sep 15 '20

Yeah I know, I’m speaking specifically about how u/DrunkHacker originally answered it. Saying “Virtual Machines” doesn’t answer the question lol

2

u/[deleted] Sep 15 '20

Ah, indeed that is fair.

3

u/james4765 Sep 15 '20

The IBM System Z mainframe has several different types of binary formats - from the 24 bit addressing space from the 1960s, to the 31 bit of the 80s, to the 64 bit of the modern machines, the z/VM operating system can run all of them in parallel. But z/VM is a hypervisor in and of itself - each running process gets its own address space, virtual disks, i/o interfaces, and network ports. It also runs Linux on Z - with each Linux VM being treated the same as a mainframe program.

Those are primarily for supporting legacy code, though - no one would be doing new development for those old ISAs unless they were doing some kind of museum or data archivist work. Everything is using the 64-bit code whenever possible.

2

u/antinutrinoreactor Sep 17 '20

Probably we can make a object file and a program which all OSes will have and then the program will make a object file of a windows executable and then you can use a linker program on Linux and vice versa

1

u/jstormes Sep 15 '20

The quick answer is yes. Any Turing complete system should be able to emulate any other Turing system.

The real answer is yes but only with a lot of work, with little return.

As others have pointed out, this has been done when a upgrade path is needed. But an OS is more than the sum of it's parts.

You have installed libraries and versions of those libraries. You have configurations and you have incompatible semantics where both system use the same word or symbol to do different things, / Vs \ as example between Linux and Windows. Then you have the processor itself ARM vs Intel vs RISC, etc...

So while it is possible the cost vs reward is not there to justify it right now.

0

u/justadude0144 Sep 15 '20

Docker containers are a way to do that.