OS: How does it work?

This is a discussion on OS: How does it work? within the Tech Board forums, part of the Community Boards category; After an exe file is created, most people are executing it by double-clicking on it, fewer people call them through ...

  1. #1
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,625

    OS: How does it work?

    After an exe file is created, most people are executing it by double-clicking on it, fewer people call them through the command line. An exe can also be called from within another exe!
    As far as i know, the OS is what initialises the program, and mostly the CPU does the rest ( please corrent me if i'm wrong )
    My problem is, if the exe code is passed to the OS, how the CPU gets informed of those instructions in order to execute them?
    In general, if the OS runs every program, who runs the OS???
    Devoted my life to programming...

  2. #2
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    A good definition of an operating system: Definitions - OSDev Wiki

    Maybe someone else can give you a link to a good overview of how OSs work, I can't remember any good links at the moment...

    Your statements are both too primitive and too incorrect to "correct" them though.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  3. #3
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,069
    One might suggest that you are attempting to do the equivalent of understanding, in detail, Einstein's Theory of General Relativity without first knowing the very basics of physics. Using your conclusions to gauge your knowledge of computing, I would suggest that you step back to basics before you attempt to tackle a more advanced topic such as what you're asking. I understand that you're eager to know how everything works, but the most efficient way to get the answer you're looking for would be to build up to it.
    Sent from my iPad®

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,606
    I would put it simply that the OS is the guardian. It reads the executables and feeds the instructions to the CPU, when and how it pleases. It also makes sure your program doesn't do "illegal" stuff.
    The OS itself utilizes the low-level capabilities of the hardware to execute itself.
    That can be how you may picture it. It's far from the "truth," as they say, but sufficient to say if you don't want to know the whole truth.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,260
    It reads the executables and feeds the instructions to the CPU, when and how it pleases. It also makes sure your program doesn't do "illegal" stuff.
    O_o

    It's far from the "truth," as they say, but sufficient to say if you don't want to know the whole truth.
    You said a mouthful brother...

    Soma

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,606
    ^_^
    I like dumbed down answers.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,467
    maxorator already gave the only explanation that matters on the link he provided. There's no need for any other. Especially wrong ones.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,606
    Feel free to point out the "wrongness" of the whole. To me, it looks like a dumbed down, perhaps somewhat incorrect, explanation of what happens.
    The best thing to do is provide a link that contains a good overview.
    If my dumbed down explanation is in error, then I will modify it to accommodate the criticism (if I am still able).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    I wouldn't have said that the OS feeds instructions to the CPU. The OS is capable of being interrupted any time there's a system call from software, an interrupt from hardware, etc... and that gives the OS a chance to take control. Hence, the OS can regulate time given to the process, what system calls it can make, etc... But when the program is running on the CPU, the CPU runs the program directly (in protected mode, of course) until an interrupt occurs. Now, with virtual memory, and the way executables and libraries are packaged (as opposed to raw binary code) and stuff, it's a lot more complex, and my statement is probably wrong in some senses too - but I'd say the biggest error is that the OS really isn't feeding instructions to the CPU.

  10. #10
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,467
    Also the bit about illegal stuff, Elysia. There's simply no such requirement that the OS should offer a safe development environment. In fact, it's not desirable at all. It would invariably complicate device drivers development for instance. And it would have to negate direct access to the hardware layer, which could complicate the development of many kinds of specialized software. The thought of an operating system like that is not unfeasible. But certainly protecting against "illegal" access or operations isn't a requirement.

    And the same can be said to some extent of even the things the operating system does indeed manage. Like memory, for instance. The cost of turning a kernel completely safe against buffer overflows is prohibitive if one wants a lean and responsive OS. Those type of tasks are delegated to runtime libraries or other tools running on top of the OS... and only if it is desirable. As you know from C++, that protection is entirely delegated to the application.
    Last edited by Mario F.; 08-25-2010 at 11:04 AM.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  11. #11
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  12. #12
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,606
    Quote Originally Posted by Mario F. View Post
    Also the bit about illegal stuff, Elysia. There's simply no such requirement that the OS should offer a safe development environment. In fact, it's not desirable at all. It would invariably complicate device drivers development for instance. And it would have to negate direct access to the hardware layer, which could complicate the development of many kinds of specialized software. The thought of an operating system like that is not unfeasible. But certainly protecting against "illegal" access or operations isn't a requirement.
    Aye, but I mean certain basic things such as what if an hardware error occurs? What if a program tries to execute an illegal instruction? What if it tries to access a memory address that doesn't exist?
    What happens if these hardware errors happens and they aren't handled? To make the computer work, I would think the OS needs to handle such low-level things?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    To make the computer work, I would think the OS needs to handle such low-level things?
    It does, but it does so primarily through interrupts, which is a fundamentally different idea from what was implied in your description. Ultimately the idea that the OS is a guardian can be a helpful one, and I wouldn't say wrong. I was merely correcting an incorrect notion about how that's done.

    I prefer to think of the OS as the allocator of resources, and the role of guarding and securing the system would be an integral part of how it decides to allocate those resources.

  14. #14
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,606
    Let's just put it at that, then. The link Salem provided might give further insight to interested parties.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Sipher, don't be discouraged, if you are interested in operating systems look into this Berkeley course available for free with recorded video lectures. The course book is also available from Amazon if you want to follow along in the reading.

    Operating Systems and System Programming | Berkeley Video Course

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting if OS is Windows???
    By Ktulu in forum Windows Programming
    Replies: 2
    Last Post: 11-19-2006, 01:49 AM
  2. inquiry from a hungry mac os x user
    By terabyter in forum C Programming
    Replies: 3
    Last Post: 06-23-2006, 09:04 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 03:48 AM
  5. compiled under windows, work for mac os?
    By Shadow12345 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2002, 09:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21