Computer Hardware
There are many components within a computer, all of which have to communicate with each other. An example of the components are:
- CPU – if your computer didn't have one… well it wouldn't be a computer! :)
- Disk Controller
- USB Controller – to control in/output devices such as your keyboard or printer
- Graphics Adapter – to control what you see on your monitor(s)
- Memory – This will be your hard drive and RAM
What an Operating System Does
So, what exactly does an operating system (OS) do? Well, no matter what operating system you’re using – be it Apple, Windows or Linux – they all have to manage resources.
The main resource an OS has to manage are the processes that compete for the CPU usage, as well as the memory (RAM); you can’t leave all the sharing to the individual programs – like heck they’ll share it! :).
Something else that an OS must deal with is to provide services. For example abstraction. Abstraction is when the OS hides details from the user, such as a reliable network connection – the OS will hide things such as checksums and retires from the user.
Processes
A process is a program in execution and not a program on the disk! Associated with each process is an address space, this is the memory locations that the process can read and write to.
Also note, that many processes can exist at any time – a process is created when a program is executed, and i am pretty sure your computer allows multiple programs to be running? :)
Threads
A thread is not a process! – a thread is part of the data that makes up a process:
- process = thread + address space
A thread is a sequence of instructions in a sequential execution context. If we have multiple threads within the same process, then we call this multithreading.
Address Spaces
Say we wanted to write a program in Assembly (ARM), then your addresses start at 0 – right? But, several such programs can be loaded into memory at the same time, and every single one assumes that their addresses start at 0!
Since this is the case, the system may pause a running program, swap it out of memory, and then later swap it back to somewhere completely different!
As you can probably tell a solution is needed to handle this relocation so that programs assume that they have the hardware all to their selves.
Virtual Machines
Operating Systems a really cool convention known as a Virtual Machine. This is a more convenient abstraction than a real machine, as applications think they use the hardware on their own! (Disclaimer: Computers don’t think… unless we’re not been told something… what if they’re all terminators or decepticons waiting to to get us! O_O)
All Virtual Machines enforce protection, whether it be protection for a program interfering with the System itself, or a program interfering with another program.
Many Operating Systems enforce this protection by adding a ‘Mode Bit’ to the hardware to indicate its current mode, be it User Mode or System Mode.
- User Mode – Execution is done on behalf of the user
- System Mode – Execution is done on behalf of the Operating System
Privileged Operations
The Operating System and hardware prevent unprivileged software from directly accessing facilities which may affect more than one program, such as File operations, I/O Operations or Memory Allocation etc etc.
System Calls
If I/O operations are privileged, then how exactly do you – the user – perform I/O?
The answer is simple, you use a System Call. A System Call is the interface between the programs and the Operating System, so it will permit application programs to access otherwise protected resources.
- System calls are a lot like functions in C/BASIC or methods in Java – such to the fact that they take parameters – or arguments…
- Once a System Call occurs control is passed to a specific routine in system mode.
- If the parameters are correct then the request will be executed.
Example
A quick example of a system call is one of the system calls from UNIX. This is a read system call which take 3 parameters:
- One to specify the file
- One to say where the data will be put
- And one too tell how many bytes will be read
So we end up with something like this:
read(int fd, char *buf, int num_bytes);
But please…. don’t confuse this with the C Library function O_O
Structure of an Operating System
A system as large and complex as an Operating System can be created by partitioning it into smaller pieces, such as:
Operating System Components
There are lots of components in an OS, such as:
- Process Management: creation, deletion and CPU allocation of processes
- Memory Management: Allocate and de-allocate memory space, and keep track of what parts of the memory are currently being used.
- Device Management: like I/O
- File and Secondary Storage Management
- Network Management
- User Interface: GUI’s and Command Line (Shell)
No comments:
Post a Comment