2
$\begingroup$

I know the fact that you cannot run the same machine code on two different machines,

so the software must be machine dependent (i.e Arm program cannot run on either powerpc or x86).

but in reality the software is OS dependent (i.e linux programs cannot run on windows or mac).

how does this happen? my best guess for now is that every OS behaves like a virtual machine and the source is compiled for windows-machine,may be?? and this machine has its own assembly code?

$\endgroup$
  • 4
    $\begingroup$ It's both OS and machine dependent. $\endgroup$ – Karolis Juodelė Nov 17 '16 at 9:50
1
$\begingroup$

You're asking a different question in the body than the title. I'll answer the question "how can a program be OS-dependent?".

There is no universal definition of an OS. At the very least you need a kernel (even then, are we building a monolith or microkernel?), but an OS also usually comes with standard (C) libraries and programs (including service daemons).

If a program uses dynamic linking to depend on a certain standard library (say the C math library), then we need to run on an OS on which that library is available. Likewise, a program may try to interact with other programs through IPC mechanisms, and if they're not running then the program will fail.

Even if we only make use of the kernel, different kernels may e.g. use different IPC mechanisms, and a program written using unix pipes will certainly not work on Windows.

$\endgroup$
5
$\begingroup$

Operating systems have Application Programming Interfaces, whose functionalities are available as libraries that are linked to the code produced by the programmer.

This does not mean they constitute virtual machines. They just encapsulate operations that are not directly accessible to the programmer, either because they depend on low level instructions or protocols that are protected, or because they are provided as high-level standard services.

What happens is simply that what you write in a language that compiles to machine code is only a part of what will be running. Usually a very small part.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.