Operating Systems Notes: 1. What Is An OS (P5)
Operating Systems Notes: 1. What Is An OS (P5)
Operating Systems Notes: 1. What Is An OS (P5)
1. What is an OS (P5)
• An OS is a layer of software which separates application software from the hardware,
and is responsible for system security and allowing multi-tasking.
• Some OSs are multi-user, allowing a machine to be used simultaneously by multiple
people.
2. Memory (P3)
• Computers hold data in a memory which is a large array of equal-sized storage spaces,
usually each holding bytes. Each location has an address, with which its contents can
be retrieved.
• Most computer memory can be written to so can be used to store variables, software
variable names are aliases for addresses.
• Most memory is Random Access Memory (RAM), meaning that all addresses can be
accessed at the same speed and at any time.
4. Caching (P3)
• Caches monitor outgoing memory requests and if it recognises the address it will
intercept the request and respond to it locally.
• A cache miss refers to a request that cannot be satisfied by the cache.
• Caches rely on temporal locality – if something was used recently it will probably be
used again, and spatial locality – if one address is used then nearby addresses will
probably be used, these principles form the basis for algorithms such as least recently
used (LRU) to decide what to keep in the cache.
5.5 Trashing
• Trashing occurs during caching when the working set exceeds the physical capacity of
the system.
6. Memory Protection (P3)
• It is often useful to protect memory from being accessed by other pages, this can be
done using memory mapping to hide memory that a process shouldn’t be able to see,
however any user needs to be able to interact with OS services.
• Access permissions can be assigned to pages which can be checked during memory
access, if there is a breach of permission based on the address, action and processor
privilege then a hardware exception can be raised to invoke the OS to deal with it.
• The access permissions are specified by the MMU may include:
o No access – can be used when a page should not be accessed and can trigger a
segmentation fault, or could be used if the page does not yet exist in physical
memory, in which case a page fault is invoked.
o Supervior read-only – used to protect OS code from being viewed by a user
process.
o Supervisor read/write – used to protect OS data, such as passwords.
o Read-only – used to protect instruction code from accidentally being overwritten.
o Read/write – normal permissions for user pages, usually not accessed by the OS.
7. Interfaces
9. Processes (P5)
• A running program is associated with a set of values, such as the owner and used
resources, the program with these values is referred to as a process.
• Most OSs allow multiple processes to run at the same time without interfering with
each other, even if they are running the same program.
• Most of a processes context will be held in memory and each process will have some
address space which it can use to store variables and code.
• The OS will store the data about a process in a PCB.
• A process will rarely run continuously, it may get blocked, e.g. waiting for a key press,
or may get set aside so another process can run.
• In Unix, each process has a parent, at boot the first process forks the init process and
then becomes the idle process, the init process goes on to create all child processes.
• The processes parent is held in the PCB.
• If a parent process terminates before its children then the children are orphaned and
adopted by the init process.
• Sometimes a process terminates without the parent being informed, causing the the
parent process to continue holding data about the zombie process until the OS
synchronises with it, this situation is usually the result of a program error.
9.1 Process States (P5)
• Processes can exist in different states to facilitate multi-tasking, a process can be
blocked, ready or running.
• A running process is a process that is currently being executed by a processor, it may
yield execution or be forced to by the OS, in which case it becomes ready,
alternatively, it may become blocked when it is waiting for an I/O resource.
• A ready process is a process that is waiting for a chance to use the processor, it will
switch to running when scheduled by the OS.
• A blocked process is waiting for an external event to take place before becoming
ready, such as I/O input or availability or if it has put itself to sleep.
• It is important that each I/O resource be owned by a single blocked process.
• A process can be terminated by an external influence when it is in any state.
• Any number of processes can be ready at a time, they will be put into a queue and
allocated time-slices by the scheduler, any number of processes can be blocked at a
time.
• The number or running processes is limited to the number of cores available.
9. 8 Synchronisation (P4)
• When multiple threads/processes are running, the schedule of their execution may
be unpredictable leading to asynchronous execution.
• When threads and processes interact it is necessary to synchronise them in order to
avoid race conditions and other errors, there are numerous approaches to
synchronisation:
o Barrier – a counter in shared memory is initialised to the number of relevant
threads/processes, then when each reaches a certain point it atomically
decrements the counter and then blocks until the counter reaches 0, at which
point all the threads are signalled to unblock.
o Thread join – a form of barrier where two threads merge into one before
continuing.
o Mutual exclusion – used to provide atomicity of a section of code.
o Asynchronous message passing – one process sends messages to its counterpart,
though it may end up sending faster than the other can receive.
o Synchronous message passing – if a process reaches a message point before the
other it blocks and waits for the other process, after which the processes
exchange information before continuing, this is introduces some overhead but
allows two way message passing.
• In some cases the synchronisation is not between processors, e.g. when a DMA
transfer is ongoing the processors must avoid accessing the relevant memory.
14. Abstraction
15. Miscellaneous