Operating Systems – OS Concepts
November 21, 2009 Leave a comment
Operating System Concepts
What does an OS do?
- It manages resources:
- The different processes running have to compete for memory, CPU etc
- You can’t leave sharing upto the individual programs as they won’t share!
- It protects resources
- It provides services
- A level of abstraction (hiding detail)
- Think about how much of what’s going on your OS actually lets you see. You never see all the checksums and memory management etc
So processes are talked about all the time, but do you actually know what they are? Me neither..
A process is a program in execution. It is not a program on the disk.
- Every process has an address space associated with it. This is all the memory locations to which the process can read and write.
Process = Thread + Address Space
- So it is a sequence of instructions laid out in sequential execution
- If there are multiple threads in the same process then this is multithreading
There are loads of processes going on at the same time on your computer. Just press Ctrl + Alt + Del (Most windows users know that key combination very well) to see them.
Think of the Little Man Computer. Every program starts at 0. But as there can be several loaded into memory at the same time, they can’t all start at 0.
Sometimes the system can pause a program and swap it to a completely different part of memory.
So basically what you need is a way of making all programs thinking they have the run of the hardware.
The operating system provides a virtual machine, which is a more convenient abstraction than the real machine. Each application ‘thinks’ (computers don’t actually think. I think.) that they have control over all the hardware.
- Protection is increased by using a virtual machine
- Buggy programs cannot interfere with the OS or other programs
The way many OSs enforce protection is by adding a ‘mode bit’ to hardware. This bit indicates whether something is in user mode or system mode. User mode means the hardware is acting on demand of the user, and system means it is acting on behalf of the operating system.
The OS prevents unprivileged software from accessing hardware that will affect more than one program. Things like… I/O facilities, memory operations, CPU allocation and network operations.
So we’ve just established that I/O calls are privileged. So as a user, how do you perform I/O? You use a system call.
A system call is the interface between user programs and the OS, so using a system call lets programs access resources that are otherwise protected.
- They take arguments, just like your methods in Java / functions in C.
- When a system call happens, control then passes to a routine which is in system mode
- If the parameters are correct then the request will be executed
Unix has a system call to read from a file. It has 3 parameters:
- The file to read
- Where to put the data when it’s read
- How many bytes to read
something like this:
read(int fd, char *buf, int bytes);
An operating system is pretty complicated. To make it seem simpler, it is partitioned into smaller pieces, something like this:
Components of the OS
- Process manager: Creates, deletes processes. Allocates CPU to processes etc
- Memory manager: Allocates memory space, deallocates it
- Device management: Input, output
- File management
- Network managemen
- User interface: GUI, shell
Services the OS provides
Let’s say you type ‘part1’ to make your part1.c run.
- The command is read
- The program file is found
- Memory is allocated for it
- The file is read into the allocated memory
- Required libraries are found
- part1 is started
- It is finished cleanly
Engineering an OS
There are several approaches
- Monolithic systems – They have absolutely no structure
- Layered approach – The bottom is the hardware, and the top layer is the UI. Each layer only uses services of layers below it, or to put it another way, each layer only provides services for layers above it. The lower layers (aka the kernel [this link actually has a very helpful image]) contains the fundamental functions to manage resources
- Big kernels tend to have problems
- Microkernels keep only minimal functionality in the OS
Join us next week for an adrenaline inducing post on process management. With a special guest star*
*may not be true