0

I read the SO question and I am still in doubt - Why an executable program for a specific CPU does not work on Linux and Windows?

One of the replies says that "Every OS requires the binaries to conform to a specific binary format."

Is that correct ? If yes, then can we add this to the above statement - Executable files contain binary code (???). Lets say 100011 means 5 in windows binary format. But these same code means something else or even nothing in another OS. So, an executable made for win will not work in linux.

Community
  • 1
  • 1
Apple Grinder
  • 3,573
  • 7
  • 22
  • 35

2 Answers2

1

Windows and Linux are built using different bases. Windows is based on DOS and Linux is based on UNIX. If Windows had released the source code for their OS, then maybe Linux would be more compatible and able to run Windows programs, but this didn't happen. Linux developed on its own so its understandable that it would be different. Among other things, Linux also uses different system commands and calls, so even though they both have "executable programs" the way in which they are executed is OS specific.

One Example: Open a command prompt in Windows and type dir. That will list all files and sub-directories of the current directory. However, the Linux equivalent to list contents of a directory is ls.

Source: Why can't linux run windows programs?

cnexus
  • 454
  • 1
  • 3
  • 14
0

A crude, plain english attempt at answering my own question -

An OS allows applications/programs to interact with the hardware - monitor, keyboard, network card etc. It acts like a middle man between apps and hardware.

Why do we need a middle man in the first place ? I don't know the answer to that, but I will guess. Maybe we could add code to our apps which will allow it to interact with all the hardware. But, if every app does this, then each app will require too much space - a waste. They will be redundancy. For example, all games will have their own code to show the screen of the game in different brands of monitor. Maybe there will be other problems too.

To interact with hardware, a program needs to "talk to" the OS or make 'system calls'. The "language" used by an OS is called an "API". Every OS has a unique API. So a program "talking" in windows API will not be able to "talk" to a linux system.

Links that I used - http://en.wikipedia.org/wiki/Operating_system http://en.wikipedia.org/wiki/System_call

Apple Grinder
  • 3,573
  • 7
  • 22
  • 35