You are on page 1of 8

Operating Systems: o An operating system consists of software that almost everything else depends on o Resource allocation Deals with:

: processors, ram, disks, network interface, display, I/O o Provides a virtual machine that allows many users use the hardware o Monolithic OS An operating system where the entire OS is stored in a single file Links all components together into one large system Runs in privileged mode o MicroKernels Only essentials running in privileged mode All other components execute in user mode Slower than Monolithic o Two Modes (User and Privilege) OS executes in privilege mode (OS switches from user to privilege when your C program calls a system level function) o Fundamental Task: process management o Switches between multiple processes o Enables efficient utilization of the processor and I/O Devices Kernel o Hub of an operating system o Allocates time and memory to programs and manages the file system and communications via System Calls o Runs in Privilege Mode Shell o Interface between the user and the kernel Processes o A program in execution identified by a PID (process identifier) o Two Characteristics Resource Ownership process includes a virtual address space to hold the process image Scheduling/Execution follows an execution path that may be interleaved with other processes Treated independently thus the use of threads o Elements Program Code Data Set Process State Attributes o Two States running and not running o Variable Weight Processes

Portions of the parent process selectively copied into or shared with the child process Children created using the clone system call Process Spawning o Parent Process original, creating process o Child new process o Process Creation: Unique PID Allocate Space Initalize Process Control Block Set up Linkage Expand/Create other data structures Process States: o Running process is running o Interruptible blocked state of a process and waiting for an event or signal from another process o Uninterruptible a blocked state, waiting for a hardware condition.. cannot handle signals o Stopped process is stopped or halted and can be restarted o Zombie process terminated but the information is still there Resource Categories o Reusable cannot be depleted o Consumable created and destroyed Trap o Invoking the kernel from user code o Unintentional request caused by a programming error (invoked through a System Call) o Caused by a current computation Interrupt o Request from an external devices for a response from the processor o Handled independently of any user program o Caused by something external to the current computation Forking (creates a UNIX process through C programming) o Creates a new processor, which is an exact copy of the process which called the fork Returns twice Once with the parent process (PID of the child), and once with the child (0) The address space of the child contains a copy of the address space of the parent o Zombie if the parent process dies and the child is already dead (nothing to pick up the dead parent) Exec()

o Original program is lost and replaced with a running copy of the new program o Overlaying Structures o Used to declare a block of data containing different data types Malloc o Allocating a specific amount of memory during program execution o Operating System reserves the requested amount of memory through the malloc() function o Must free() the memory after use Threads o Executes independent of its creator o Need a stack to hold thread context o pthread_create return successfully (0) executes independently o When terminates goes into a Zombie state, and when another thread calls pthread_join, on the terminated thread the thread is released and the id can be reused o Has the following: Execution State Execution Stack Static Storage of local variable Access to the memory and resources of its process o Take less time to create and terminate than a process o Switching between threads is faster o Can communicate without the use of a kernel o User-Level Threads Management done by the application Kernel is unaware of its existence o Kernel-Level Threads lightweight processes Maintains context information for the process and threads Scheduling is done on a thread basis Advantages: Simultaneously schedule multiple threads from the same process on multiple processors The kernel can schedule another thread of the same process if one thread is blocked Disadvantages Transfer of control from one thread to another requires a switch to the kernel (more time consuming) o Kernel Level vs. User Level Kernel level are created and scheduled by the kernel and are more expensive to create. User level threads cannot be run in parallel on multi-processor systems

Multi-Threading o Ability of the OS to support multiple concurrent paths of execution within a single process Context o Setting in which execution is occurring Deadlock o When each process in the set is blocked awaiting an event that can only be triggered by another blocked process in the set Usually involves processes competing for the same set of resources o Conditions for a deadlock Mutual Exclusion only one process may use a resource at a time Hold-and-wait may hold allocated resources while awaiting assignment of others No Pre-Emption no resource can be forcibly removed from a process holding it o Actual Deadlock Needs previous 3 and Circular Wait a closed chain where one process holds a resources that the next process needs o Dealing with Deadlock Prevent, Avoid, Detect Prevent Strategy Indirect prevent all three of the necessary conditions occurring at once Direct prevent circular waits Avoidance Process Initiation Denial o Do not a start a process that may lead to a deadlock Resource Allocation Denial o Do not grant incremental resource requests to a process if it may lead to a deadlock Pipes o Circular buffer allowing two processes to communicate on the producer-consumer model First-in-First-Out queue Semaphores Signals o Informs a process of the occurrence of asynchronous events o Notification sent from the software to the process, basically interrupts the processs normal flow of execution o Signal Handlers catch signals Static Linking and Loading

Linking the process of collecting and combining various pieces of code and data into a single file that can be loaded into memory and executed o Static vs Dynamic: Static is loaded into the program while dynamic is hooked into the program but isnt actually in the program Dynamic Produces a smaller executable Hard Links vs. Soft Links o Hard links cannot point to a directory, it is directly tied to something and contains everything it points to o Soft Links point to the file like a pointer does in C Compilation o Four steps Executing the preprocessor Compiling the C code into Assembly Language Compiling the Assembly Code into Object Code Linking the Object Code to create an Executable File Libraries o A File containing several objective files o Can use an entire library as a single entity when linking a program o Static: Linked into the programming during the linking phase of compilation Inserts the objective files from the static library into the executable o Shared/Dynamic: During compile time the compiler makes sure the library is linked properly During execution they are loaded into memory and attaches them to a copy of the program in memory o Pre-relocation relocate libraries ahead of time o Limited Sharing relocate separately for each process o Position Independent Code no need for relocation BIOS o Basic Input/Output System Non-Volatile RAM o Three primary functions Power on self test Load and transfer control to boot program Provide drivers to all devices Memory Tables o Used to keep track of main and secondary memory File Tables o Provide information about Existence of files

Location in secondary memory Current Status Other attributes Process Tables o Know details: Current State PID Location in Memory o Process Control Block Process Image collect of program: data, stack and attributes Modes of Execution o User Mode less privileged o System Mode kernel level Scheduling o Dynamic: Priorities are scheduled during execution System Types: o Multi-Programming Batch Systems Execute multiple jobs concurrently, sharing processor time between the executing jobs o Time-Sharing Systems Sharing the computing resources among many users o Share Servers Same as multi-programmed batch systems now-a-days Share a single computers processing time among many clients o Real Time Systems o Strategies: First-In-First-Out Single job queue Each job runs to completion Shortest-Job-First Chooses the job with the shortest remaining execution time Round-Robin Queue Each process is executed for a quantum amount of time, interrupts the process, moves the process to the end of the queue and selects the process at the front of the queue o Favors shorter processes Multi-Level Feedback Queue Prioritized Queue or several queues with different priorities Run each for a quantum amount of time, and lower the priority of the process until it reaches the lowest priority

Virtual Machines o Efficient, isolated duplicate of a real machine o A means for structuring an operating system Virtual Machine Monitor (VMM) o Runs in privileged modes o Used to multiplex system resources File System o Easy-to-use permanent storage o Needs: Directories File Access o Criteria Easy Access High Performance Permanence Security Disk Read/Write Steps o Position The read/write head over the correct cylinder o Rotate the disk platter until the desired sector is underneath the read/write head o Rotate the disk platter so the head can read/write the entire sector Reducing Seek Time o Keep related things close to one another o Separate unrelated thing Crashing o How to Cope Dont Crash Perform multi-step disk updates in an order such that the disk is always consistent Consistency Preserving Approach Perform multi-step disk updates as Transactions o Transactional Approach Treats a series of file system updates as Atomic Transactions Atomic Consistent Isolated Durable Two Types Journaling o Record previous contents (undo journaling) o Record New contents

Keeps track of changes, it is a circular log in case there is a crash these things will be more easier to bring back and less likely to be corrupted Shadow Paging o Steps of transaction written to disk, but old values remain o Single write switches old state to new

Virtual Memory o Paging divide the address space into fixed-size pages Mapping virtual addresses into real addresses Page A page of Virtual Memory Page Frame Subdivision of primary memory o Segmentation divide the address space into variable size segments o Performance Trap Occurs (page fault) Find free page frame Write page out if no free page frame Fetch Page Return from Trap o Global vs Location allocation Global all processes compete for page frames from a single pool Local Each process has its own private pool of page frames

You might also like