35

What is different about the way Windows runs an executable and Linux runs an executable? Why did they have to be different? Besides, why don't Linux executables have a file extension?


I'm not asking about how to make a EXE file work on Linux.

I'm asking why it does not work.

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
Nav
  • 1,049
  • 3
  • 14
  • 28

3 Answers3

54

Linux and Windows executables use different formats. Linux uses the ELF format on most architectures, while Windows uses the PE format. ELF is better suited to the way Linux manages shared libraries, and PE is better suited to the way Windows manages shared libraries, but there's no fundamental reason why Linux couldn't execute PE executables or Windows ELF executables. In fact Linux can execute PE executables, through Wine.

The difficulty is that Windows and Linux have completely different APIs: they have different kernel interfaces and sets of libraries. So to actually run a Windows application, Linux would need to emulate all the API calls that the application makes. That's a lot of work. Wine does it to some extent, but it's very hard, especially since the maker of Windows doesn't cooperate. You can compare it with, say, learning English when your native language is Chinese: the executable format is the alphabet (not that hard to master), the API is the vocabulary (takes years to get to a level where you can start reading literature).

Gilles 'SO- stop being evil'
  • 69,786
  • 21
  • 137
  • 178
  • 11
    "Vocabulary" is an excellent analogy. – Dennis Williamson Nov 11 '10 at 18:32
  • I think you meant completely *different*. – Mircea Chirea Nov 11 '10 at 21:28
  • Android also supports Linux bnaries(not packages) if they are compiled for ARM because it is based on Linux – Suici Doga Feb 20 '16 at 08:11
  • @SuiciDoga Sort of, but it's more complicated than that. The Android kernel can run Linux binaries (if they're compiled for the right kernel ABI, e.g. wrt the use of NEON registers), but if you want to run dynamically-linked programs, you have to install all the libraries as well. (And if you do that you could install a package manager too, so “binaries but not package” isn't really true.) – Gilles 'SO- stop being evil' Feb 20 '16 at 14:01
  • Yes ,I know about that you have to change library path etc – Suici Doga Feb 20 '16 at 15:32
  • You can actually install adebian chroot which is real Linux without destroying andtoid – Suici Doga Feb 20 '16 at 15:33
  • @Gilles So does it mean that executables will contain system calls which are not elementary CPU instructions, i.e., these calls needs to be further 'translated' by operating system's API so the CPU can read them? If that is the case, why can't we just let the API or ABI on Windows translate them first and then it will run on Linux because now the CPU will understand everything? – Kun Dec 31 '16 at 00:29
  • @Kun That's called a virtual machine. – Gilles 'SO- stop being evil' Dec 31 '16 at 19:30
  • @Gilles I am saying letting windows api trasnlate the system calls directly to cpu instructions which fetch data from peripheries rather than translating these system calls to Linux API readable format. Is that possible? – Kun Dec 31 '16 at 19:43
  • @Kun If the peripherals are in use by Linux at the same time, that isn't going to work, because Linux and Windows will conflict with each other. For example, there needs to be separate areas in memory for Linux and Windows. Separating the areas is the role of the VM hypervisor. Linux and Windows can't both receive keyboard events; some software (again the hypervisor) has to decide which gets which when. And so on. – Gilles 'SO- stop being evil' Dec 31 '16 at 19:51
  • @Gilles i think I am actually referring to this situation: consider two machines, one running windows and another Linux. Since windows executable contain system calls to windows API, can't to let windows further compile these API to CPU readable codes. Now the executable no longer contain any system specific API, only CPU readable instructions, so shouldn't that then run on the Linux machine? – Kun Dec 31 '16 at 19:56
  • @Kun First, an OS doesn't compile code. What code gets executed depends on external events (timing of interrupts, data read from peripherals), it isn't reproducible. Second, even if you managed to record execution and reproduce external events, that still wouldn't solve the issue of conflicts: the hardware used by Windows wouldn't be usable by Linux. You can solve this by presenting fake hardware to Windows — in other words, running Windows in a virtual machine. – Gilles 'SO- stop being evil' Dec 31 '16 at 20:02
  • @Gilles thanks. I see why external events can interfere with the code execution and make it difficult for executable to run on another system. You also said that the hardware used by Windows wouldn't be usable by Linux, but what does it mean? Many computers nowadays support both Windows and Linux. Do you mean the hardware driver API are different? – Kun Jan 03 '17 at 16:24
  • @Kun No, I mean that they can't use the same hardware at the same time, because each OS expects to find the hardware in the state it left it. – Gilles 'SO- stop being evil' Jan 03 '17 at 17:46
  • @Gilles oh, I see. That's probably fine as long as we don't have two systems running on the same hardware. – Kun Jan 03 '17 at 17:48
  • @Kun Sure. But the hardware includes the CPU itself, and the RAM, so basically they can't run on the same computer at the same time. – Gilles 'SO- stop being evil' Jan 03 '17 at 17:51
  • @Kun That's what hardware virtualisation basically is. Hardware support for virtualisation means that multiple operating system can control the "same" hardware at the same time. But you need a privileged hypervisor (a virtual machine manager) to manage the real hardware access though, since the guest machine actually only runs with virtualised privilege on the hardware. There's also what's called hardware "pass through", which essentially the host machine sets it up so the guest has full control over a specific hardware. – Lie Ryan Jul 20 '23 at 02:28
  • With pass through, the host machine only retains control over the communication channel with the hardware (e.g. PCI-E), but the traffic is passed through the hardware essentially unmodified. This allows the guest to, for all practical purposes, have sole control over that piece of hardware. – Lie Ryan Jul 20 '23 at 04:06
14

Windows binaries have a different ABI and use a different API than Linux binaries.

Linux binaries don't need an extension because *nix uses permission bits to identify an executable instead of the extension.

Ignacio Vazquez-Abrams
  • 111,361
  • 10
  • 201
  • 247
  • 1
    Agree with the answer...additional piece of data that may be relevant: ELF(http://en.wikipedia.org/wiki/Executable_and_Linkable_Format) vs PE(http://en.wikipedia.org/wiki/PE_executable) – RobotHumans Nov 11 '10 at 13:33
  • Ah yes, it needs a different loader as well. http://en.wikipedia.org/wiki/Loader_%28computing%29 – Ignacio Vazquez-Abrams Nov 11 '10 at 13:35
  • I especially like the second piece of information missing from the answer by @Gilles. – Timothy Gu Dec 07 '14 at 06:01
  • @IgnacioVazquez-Abrams That's very interesting. What if i told you that i just run a windows game PlantsVsZombies.exe on Ubuntu 16.04 Linux natively? I just did that out of boredom knowing that it would not launch, but it did and i could play it perfectly fine. That's like impossible, because that game needs the steam api to run first and it clearly didn't. How did it launch??? Should i make a new question for that? – KeyC0de Feb 24 '17 at 19:56
  • @RestlessC0bra: Wine and Mono are things. – Ignacio Vazquez-Abrams Feb 24 '17 at 21:15
  • @IgnacioVazquez-Abrams Not sure what you mean. So this game includes the Mono emulator? But i downloaded it from Steam! Anyway. Yeah, i understand it must include some kind of emulator to be run cross platform. – KeyC0de Feb 24 '17 at 21:35
0

This is how I heard the Windows side explained in layman's terms from programmers.

In Windows there are hooks in programs and the OS that EXE files make calls to that just won't be there in Linux. Because of the differences in both the environments. Initially Linux looks for permissions, and Windows looks for a linkable format first by examining the extension, looking at properties, and then looking inside the EXE file, etc.

There are applications like Netbackup that started out on Linux and have been modified to run in a Windows environment without using Wine. IMHO, frequently those are some of the most stable best behaving Windows applications.

When Windows applications become unruly usually it is because some of those hooks held by the application weren't completely released and Windows thinks they were (memory leaks). When Windows hands that unreleased memory space out to another application, it crashes and burns.

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
Bill
  • 1
  • 2
    Somehow I'd like to believe that Bill Gates answered my question ;-) – Nav Jul 31 '16 at 17:24
  • Re *"When Windows hands that unreleased memory space out to another application, it crashes and burns."*: That doesn't sound plausible, even in 2010. – Peter Mortensen Dec 18 '20 at 16:55