---
# System prepended metadata

title: Week 1 Cohort 1

---

# Week 1 Cohort 1

## Operating System
A program that acts as an intermediary between the computer user and the computer hardware. It is a non-terminating program; it is in an endless loop.
The development lifecycle is the same as other program (coded and compiled).

As a supervisor software, there are system-level (applied to the whole system) objectives that an operating system must fulfil. These objectives are:
* Execute user programs and make solving user problems easier
* Make the computer system more convenient to use
* Use the computer hardware in a more efficient manner


## Computer System
![](https://i.imgur.com/4FbqQdH.png)

A computer system is divided into four `layers`:
* Hardware
* Operating System
* Applications
* Users

These layers of abstraction are done so that we can focus on development within each layer. i.e. If we are developing an application, we don't need to worry too much about the OS layer. The idea is to build on the layers from the hardware up, so that we could ensure that each layer is stable before going up the layers of abstraction.

## Roles of OS
### Resource Allocator
Manages the resources (Hardware layer) between conflicting requests (Application layer).
### Control Program
Provides and polices the interface for users to access the programs so that the execution of programs could be monitored, preventing errors and improper use of the computer.
Any OS-level program (`system program`) that invokes the system call is known as a `service`.


## OS Overview
There is no universally accepted definition on what constitutes an OS.
The more precise definition of the program that runs at all time on the computer is the `kernel`.
The kernel has special privileges:
* Executing instructions (includes disabling and handling interrupts)
* Full memory access

There is a special register that is used to determine the current status of the computer, Processor Status Register (PSR).


## OS Boot
Bootstrap program is the program that `boots up` an Operating System kernel. This program is typically stored in ROM or EPROM, generally known as firmware. It initializes all aspects of system.
When the system first boots up, the CPU is run on the supervisor mode, since we have to access the kernel space to initialize the programs.

## Computer System Organization
CPUs and device controllers compete for access to the memory. They are all connected through a common bus that provides access to this shared memory. 
The coordination between the different devices is handled by the kernel through a mechanism known as *interrupts*. Thus, these devices are known to be interrupt-driven. 

### Interrupt Architecture
The OS Kernel needs to know which device sends the interrupt. There are 2 ways to do it:
* Polling Interrupt : Interrupt signal is sent without sending the address of the device that requests for the interrupt. Polling is done to check which device that reqeusts for this interrupt.
* Interrupt vector: Interrupt signal is sent along with the address of the device. This way, there is no need to do any polling, which is computationally expensive.

### Trap
Application-level, software-generated interrupt caused either by an error or a request by user code. Trap is the instruction that allows us to go from the user mode to the kernel mode.

### Fault/Exception
This is another form of software interrupt. When there is an error in the code, it may lead to an exception, which will terminate the program.
The CPU will check for the presence of serious errors, and will immediately invoke the appropriate handler via the event-vector table.

### System calls
Done by kernel to interact with the different applications, e.g. reading/writing, mouse clicks.
Hence, modern OS's are interrupt driven, since they have to handle system calls, which are software interrupts.
