views:

283

answers:

7

I just wonder, can we execute a program on a machine without an operating system?

Besides, I heard that the Linux kernel is written in C language and a kernel is run during booting, so I just wonder how a computer understand the language without first compiling?

+6  A: 

the linux kernel might be written in C. It is still compiled to machinecode. And it is this machine code which is executed during boot

You can also write software which is run during a boot. This way you can make your own custom OS, or make your own custom software which can run without an OS directly. Beware though, that an OS gives you a lot of functionality which you'll have to make yourself. Things like driver support, disk IO routines, networkstacks, multitasking and memory management you'll have to do yourself.

Finally: I don't think people don't like it that much if they have to reboot their machine in able to run your software. So I'd go with writing for an OS... it makes live easier on you and the user.

Toad
Users could use virtualization (and indeed many DRM proponents are seduced by the very idea of not relying on the host OS -- the "trusted computing" initiative).
Pascal Cuoq
But of course, you can't totally trust the hardware either... DRM just isn't possible.
Andrew McGregor
So that's mean every operating system like windows is a software??Then how bout the day before operating system was created??And does a bootloader need to be written in assembly low level language??
yes, an OS is a piece of software too. It is a piece of software which allows other pieces of software to run together and use it's functionality.
Toad
As for the days before operating systems were created: you manually loaded a program into memory somehow and told the computer to start executing from location 0. (which is still what it does today, but the thing it starts executing is the boot strapper)
Pod
@pod: actually. typically on location 0 was an address stored where the processor should start executing
Toad
depends. ARM beings execution at 0, and 0 is usually "jump to xxx".I'm not sure if x86 does it that way or read it like you say, but still, the principal is essentialy the same ;)
Pod
I've personally used a computer where to boot it, you first loaded a 12-byte program into ram by flipping toggle switches on the front panel to write the bytes directly. You learned to do this quickly after a while. That short program did nothing more than instruct the disk controller to read a sector to a buffer in ram, wait for it to happen, then jump to the first byte of the buffer. If you toggled it in without errors, that is.
RBerteig
+6  A: 

In short, yes.

Linux is still a software program, in machine code, that runs on a bare metal machine. While you can execute a software program without an operating system, your program will need to implement ALL the code that is used to talk to various pieces of hardware in a computer to various degrees - e.g. outputting data to a display, interpreting input from a keyboard / mouse / network card etc. (Some of the very low level stuff are implemented by the firmware in computer components, but the rest your program will have to implement). This makes it very time-consuming and difficult for you to write something that runs entirely without an operating system.

futureelite7
+5  A: 

From Wikipedia:

When a computer is first powered on, it does not have an operating system in ROM or RAM. The computer must initially execute a small program stored in ROM along with the bare minimum of data needed to access the nonvolatile devices from which the operating system programs and data are loaded into RAM. The small program that starts this sequence of loading into RAM, is known as a bootstrap loader, bootstrap or boot loader. This small boot loader program's only job is to load other data and programs which are then executed from RAM.

The computer can understand the Linux kernel because it has already been compiled and stored (usually) on disk. The bootloader gives the computer enough functionality to load the precompiled kernel into memory.

You wouldn't need to load a whole operating system to run a program on a computer, you could write a bootloader to kick off a program you had compiled. You would not have access to any of the operating system calls that make life easier for programmers.

mattjames
The bootloader *is* "software".
dmckee
+6  A: 

Yes, and it is done today for small microcontrollers with a few KB of memory.

The program is typically written in C and compiled on some other computer (that is called cross-compiling) and then loaded as binary data into the flash memory of the controller.

starblue
+2  A: 

What is an operating system if not software running on a "bare" machine? Voodoo? XD

fortran
Don't know about voodoo, but Windows *definitely* does some necromancy somewhere along the line.
Tom Anderson
+1  A: 

Just look at any games console prior to the 32 bit ones. Almost all of them lacked any boot code at all, and simply booted directly from the inserted cartridge.

yosser
A: 

1st: Sure. You don't really need an operating system just to burn some cycles.

You might need some kind of OS support if you want to load or store files or data, manage input or output, but this can also be done calling BIOS functions directly: read key from keyboard, write to some screen or LED or serial interface. Only when you want to run multiple programs, or deal with interrupts from outside, conflicting ressources or such, then you will desperately need an OS.

2nd: The kernel is compiled to machine code, which executed during boot. There's no C involved when running a kernel. C only helps writing a kernel or any program which should run, if in the kernel or "bare metal".

rurban