The operating system is a piece of software whose job it is to take the base hardware of a device and turn it into a usuable machine for the user. It acts as the intermediary between hardware and user-usage, allowing the user to easily interact directly with the hardware; even when the user does not know they are accessing the hardware.

Examples of operating systems include:

  • Unix
  • Linux
  • Windows
  • Mac OS
  • IOS
  • Android
  • Memory manager
  • Process manager
  • Device manager
  • File manager
  • Network manager
  • Preserves and protects the space in main memory that is occupied by the operating system
  • Checks validity of each request from memory space. Verifies whether or not a user request is valid.
  • For valid requests it allocates areas of memory not already in use for this.
  • In a multi user system it keeps track of which users are using which section of memory.
  • It deallocates sections of memory once they are finished with.
  • Creates processes when neccesary to carry out tasks
  • Performs initalisation of new processes
  • Keeps track of the status of processes
  • Assigns processes to the CPU when available
  • Changes process states as events occur
  • Handles termination of proceses on completion or abort
  • Handles inter-process communication
  • Manages process queues and priorisation
  • Allocates systems devices
  • Deals with multiple requests for same device
  • Performs communication with the device during operation
  • Deallocates devices
  • Organises all files
  • Manages location of files
  • Enforces restrictions on files
  • Deals with standard file operations (delete, make new, etc)
  • User interrupts via keyboard / mouse usage
  • Completion of an I/O task
  • Power on or off
  • A Central Kernal
  • resides permenetaly in memory
  • performs low-level, frequently needed tasks
  • A set of processes
  • May be created by kernel or to service user activity
  • Processes interact with kernel via system calls
  • Create processes, run programs, open files
  • Kernel and some system processes may operate in privledged mode.
  • unique process ID
  • User ID of process owner
  • process state
  • position in memory
  • accounting stats (time used etc)
  • resources allocated (open files, devices)
  • register values (instruction pointers)
  • Running
  • On a uniprocessor machine, only one process can be executing at any time. The process that has the CPU is said to be the running state.
  • May be interrupted at end of time slice if no I/O requests or system calls performed.
  • Ready
  • Refers to a process that is able to run, but does not currently have the CPU
  • Waiting
  • Stays in the same process
  • New program overwrites caller
  • Child is identical to parent.
  • parent of all other processes
  • spawns daemon processes
  • spawns process for user login
  • Printer spooler
  • Email servers
  • FTP server
1 - hang up2 - interrupt3 - quit6 - aboort9 - kill14 - alarm15 - software termination signal

The process can choose to ignore the signal, it does not have to terminate.

However you cannot ignore the kill signal, it HAS to take effect.

A process can “catch” a signal

Kil all sends the signal to all processes with a given range of PID or with a name or a sub name.

Pipes and Sockets

A pipe is a command that allows it to pipe data into something. It attaches the standard output of one program to the standard input of another.

Sockets

A socket is a communication endpoint of a channel between two processes.

Unlike pipes, the processes:

  • do not have to be related to eachother Unlike processes where each process spawns from process 1, they all have the same lineage sockets do not need this.
  • do not need to be on the same machine
  • do not need to be on the same local-area network (LAN)
  • program counter
  • its own stack space
  • program code
  • data
  • open files
  • example 1 — a web browser
  • one thread for retriving data from internet
  • another thread displays text and images
  • example 2 — a word processor:
  • one thread for display
  • one for responding to key strokes
  • one for spell checking
  • Ease of programming Many applications need ot perform several distinct tasks simultaentously
  • Responsivness In a web browser the user waiting for the image to download but cna sitll interact with other parts of another part of the page
  • Resource sharing threads share memoryh and resources of the process they belong to
  • Economy Threads are more economical to create and context switch as they share resources
  • Utilisation of parallel architectures In a multiprocessor architecture, where each thread may be running in parallel on a different processor, the benefits of multithereading can be increased.
public void inc() { count = count + 1; }

Let’s assume that count is initially zero and we have two threads, T1 and T2 and they both call the increment method.

Indeterminacy means we cannot determine the outcome.

Mutual Exclusion

Indeterminacy arises because of possible simultaenous access to a share resoruce.

Solution is to only allow one thread to access a variable.

When a thread / process accesses any shared resource, it is in a critical section.

One way to enforce mutual exclusion is via semaphores.

Semaphores

A semaphore is an integer-valued variable that is used as a flag to signal when a resource is free and can be accessed

Only two operations possible, Wait and signal. Also called p and v, test and increment, down and up.

Wait() signal ()

Wait and signal are indisible. When one thread / process is executing the code in square brackets, no other may do the same.

They can also be used to enforce mutual exclusion.

There situations where you may want more than 2 threads to get access to a resource.

Syncrhonisation problems

There are a number of famous problems that charecterise the general issue of concuerrency control.

One of them is called

Producer-Consumer problem

Syncrhonisation: The producer-consumer problem

A producer process (eg secretary) and a consumer process commmunicates via a buffer.

The secretary puts the letter in a letter tray and the manager picks up and processes that lecture.

Both running in parallel

  • Producer cycle
  • produce item
  • deposit in buffer
  • consumer cycle
  • extract item from buffer
  • consume item
  • producer cannot put items in buffer if it is fully
  • Consumer cannot extract items from buffer if it is empty
  • Buffer is not accessed by two threads simultaenously
  • no cycles in this graph mean there is no deadlock
  • diagraph

Originally published at brandonskerritt.github.io on February 20, 2018.