C Board  

Go Back   C Board > Community Boards > Tech Board

Reply
 
LinkBack Thread Tools Display Modes
Old 01-10-2007, 09:38 AM   #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
kris.c is offline   Reply With Quote
Old 01-10-2007, 11:04 AM   #2
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,492
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
CornedBee is offline   Reply With Quote
Old 01-10-2007, 11:05 AM   #3
Jaxom's & Imriel's Dad
 
Kennedy's Avatar
 
Join Date: Aug 2006
Location: Alabama
Posts: 877
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).
Kennedy is offline   Reply With Quote
Old 01-10-2007, 11:06 AM   #4
Protocol Test Engineer
 
ssharish2005's Avatar
 
Join Date: Sep 2005
Location: fseek(UK)
Posts: 1,324
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.
ssharish2005 is offline   Reply With Quote
Old 01-10-2007, 01:21 PM   #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
kris.c is offline   Reply With Quote
Old 01-10-2007, 01:24 PM   #6
Crazy Fool
 
Perspective's Avatar
 
Join Date: Jan 2003
Location: Canada
Posts: 2,596
The answer to both is "yes", just define "machine" as a hardware implemented C interpreter
Perspective is offline   Reply With Quote
Old 01-10-2007, 01:31 PM   #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
kris.c is offline   Reply With Quote
Old 01-10-2007, 02:01 PM   #8
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,492
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.

Quote:
> 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.

Quote:
@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
CornedBee is offline   Reply With Quote
Old 01-10-2007, 02:37 PM   #9
Jaxom's & Imriel's Dad
 
Kennedy's Avatar
 
Join Date: Aug 2006
Location: Alabama
Posts: 877
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.
Kennedy is offline   Reply With Quote
Old 01-10-2007, 02:45 PM   #10
Crazy Fool
 
Perspective's Avatar
 
Join Date: Jan 2003
Location: Canada
Posts: 2,596
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.
Perspective is offline   Reply With Quote
Old 01-10-2007, 02:58 PM   #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?
Baccarat is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 12:46 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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