Thread: An interview question

  1. #1
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342

    An interview question

    A friend of mine was asked the following questions:

    1) Can I execute a C program on a machine without an OS?

    2) I have 2 machines. One has an OS, the other doesnt. I have to execute the program on the second machines by using the first machine.

    Any ideas?
    About the second one, even to login to the second machine, i need the support of the OS on the second machine,right? Is it even possible?
    In the middle of difficulty, lies opportunity

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    1) Depends on what you call an OS. If you call a bootstrapper that just loads the program from a known disk location and jumps there an OS, then the answer is no.
    It is just about impossible (and anyway not a good idea) to write such a bootstrapper in C - that's still the exclusive realm of assembly or even lower levels.
    On the other hand, if the bootstrapper doesn't count, then the answer is obviously yes. Most OSs themselves are, after all, C programs.
    However, this is where the distinction between a hosted and a freestanding C implementation is important. The hosted implementation is what you're used to: starts with main(), provides the runtime library, all that nice stuff. A freestanding implementation is bare-bones: it might start anywhere, provides whatever it wants as a library, and so on. Without an OS, you'll most likely only have a freestanding C implementation at your disposal.

    2) What is meant with "by using the first machine"? You'd have to compile the program on the machine with the OS, most likely, but I can't imagine anything beyond that.
    A machine without an OS doesn't have a concept of a login.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    1) Yes.

    2) Depends on what the BIOS does/looks for at boot. I'd guess there would be something along the lines of looking for code via Serial or some other communication device. . . like, for example, a chip programmer (what's it called??? JDEC Programmer or something. . . cannot remember at the moment. I'll edit if I remember -- or someone else can correct me).

  4. #4
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Well the second one, we have something like network boot, which mean that the system can boot through network. You can actual configure this on your BIOS setup. If this was possible you actual do something like what u wanted.

    But dont no the indetails concept of it. U might get some help from others. Hope you get an idea of possibility of your application.

    ssharish2005
    Last edited by ssharish2005; 01-10-2007 at 11:08 AM.

  5. #5
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    @CornedBee : So, if i can tell the bootstrapper where my C code is ( assume this is done) , i can execute that C program. Right?
    > What is meant with "by using the first machine"?
    I meant, the first machine is used as the interface between the second machine and the user, but the actual work is done by the second machine.

    @Kennedy :
    >1) Yes.
    Are your thoughts also similar to cornedbee's? If no, could you please elaborate?

    @ssharish:
    yeah, the network boot seems to be a good i dea, i will look into more stuff on that..

    thanks.
    In the middle of difficulty, lies opportunity

  6. #6
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    The answer to both is "yes", just define "machine" as a hardware implemented C interpreter

  7. #7
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    @Perspective : could you please elaborate on how exactly one goes about? Or is it all, already there on this page?
    In the middle of difficulty, lies opportunity

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Quote Originally Posted by kris.c
    @CornedBee : So, if i can tell the bootstrapper where my C code is ( assume this is done) , i can execute that C program. Right?
    Assuming the C program is compiled for that CPU and doesn't expect any services at all, yes. But I mean it: no services. It's time to directly manipulate that graphics memory to get your output on the screen.

    > What is meant with "by using the first machine"?
    I meant, the first machine is used as the interface between the second machine and the user, but the actual work is done by the second machine.
    That would require network communication, i.e. a network stack. Sure, you can implement that in C, but you do this, and then you do that, and before you know it, your program has an integrated operating system.

    @ssharish:
    yeah, the network boot seems to be a good i dea, i will look into more stuff on that..
    Network booting is for obtaining an OS from somewhere on the network instead of a local storage medium. Do that, and the second PC is no longer without an OS.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Quote Originally Posted by CornedBee
    It's time to directly manipulate that graphics memory to get your output on the screen.
    Assuming you are in Protected Mode. In real mode you could always int 10h.
    Quote Originally Posted by CornedBee
    That would require network communication, i.e. a network stack. Sure, you can implement that in C, but you do this, and then you do that, and before you know it, your program has an integrated operating system.
    Again, access through the Serial port doesn't require any networking at all -- or through a programming station module.
    Quote Originally Posted by CornedBee
    Network booting is for obtaining an OS from somewhere on the network instead of a local storage medium. Do that, and the second PC is no longer without an OS.
    Not always. On embedded systems there is limited control given via the serial interface (sometimes). This would allow the programmer access to various parts of the system for programming -- ie, writing to the onboard flash chips.

  10. #10
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by kris.c
    @Perspective : could you please elaborate on how exactly one goes about? Or is it all, already there on this page?
    Think about how you would write a C interpreter, but instead of doing it in software, create it in hardware. If "machine" is defined as this beast that you have just built, then you can run your C program on the machine without an OS.

    It's a "thinking outside the box" answer.

  11. #11
    Registered User
    Join Date
    Jan 2007
    Posts
    8
    Quote Originally Posted by Kennedy
    1) Yes.

    2) Depends on what the BIOS does/looks for at boot. I'd guess there would be something along the lines of looking for code via Serial or some other communication device. . . like, for example, a chip programmer (what's it called??? JDEC Programmer or something. . . cannot remember at the moment. I'll edit if I remember -- or someone else can correct me).
    An FPGA/CPLD/PAL programmer?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  3. Job Interview Coming Up
    By adamg in forum C Programming
    Replies: 5
    Last Post: 05-02-2004, 11:25 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM