CSC 343 Operating Systems Midterm Chapters 1-5 By Shaan Badlu
Process
A program in execution
Shared Memory
A region of memory that is shared by cooperating processes is established. Process can then exchange information by reading and writing data to the shared region
Operating System
A program that manages a computer's hardware. It acts as an interface or intermediary between a user of a computer and the computer's hardware Execute User Programs and make solving user problems easier Make the computer program easier to use (Convenience) Use the computer hardware in an efficient manner (Efficiency)
Semaphore
A protected integer variable that can facilitate and restrict access to shared resources in a multi-processing environment. Problem it solves: Overcome the need for busy waiting
Concurrency vs Parallelism
Concurrency - Supports more than one task by allowing all the tasks to make progress Parallelism - It can perform more than one task simultaneously.
Multiprocessor System
Contains more than one CPU, allowing them to work in parallel.
Interrupt vs Trap
Interrupt - An event that occurs that executes a program. Trap - Software generated interrupt caused by either error or by a specific request from a user program that an operating system service be performed.
Firmware
It initializes all aspects of the system from CPU registers to device controllers to memory contents. It's stored in ROM.
Variables used in Peterson's solution
J and i J used to denote other processes and i is used as a process in the critical section
Scheduling Queues
Job Queue - Consists of all the processes in the system Ready Queue - Processes that are residing in main memory and are ready and waiting to execute are kept here Device Queue - The list of processes waiting for a particular I/O device
Schedulers
Job scheduler (long term) - Selects processes from a pool and loads them into memory for execution CPU scheduler ( short term) - Selects from among the processes that are ready to execute and allocates the CPU to one of them Medium term scheduler - Reduces the degree of multi programming if it can be advantageous to remove a process from memory
Memory Management
Keeping track of which parts of memory are currently being used and who is using them Deciding which processes and or parts of processes and data to move into and out of memory Allocating and deallocating memory space as needed
Simple Structure
MS DOS, started off as a small simple and limited systems. No dual mode and no hardware protection
Multithreading models
Many to one - Maps many user level threads to one kernel thread One to one - Each user thread is mapped to one kernel thread Many to many - Multiplexes many user level threads to a smaller or equal number of kernel threads.
Pthreads
May be provided as either a user level or a kernel level library. pthread_create() - Creates a new thread within a process pthread_join() - Suspends execution of the current thread and waits for the target thread thread to terminate
Mechanism vs policy
Mechanism - Determine how to do something Policy - Determine what will be done
Single Processor System
On a single processor system, there is 1 main CPU capable of executing a general purpose instruction set, including instructions from user processes.
Privileged instruction
Only in kernel mode, the instructions can be executed. This is to prevent user mode from executing them because its a way of protecting the operating system from errant users. Ex: Turn off interrupts, clear memory, set value of timer, modifies entries in device status table
Hybrid Structure
Operating systems that combine different structures. They address performance, security and usability issues. Examples: Mac OS X, IOS, and Android
Implicit Threading
Transfer the creation and management of threading from application developers to compilers and run time libraries
Message Passing
Communication takes place by means of messages exchanged between the cooperating processes.
Asymmetric vs Symmetric Multiprocessing
1. Asymmetric Multiprocessing -each processor is assigned a specific task. 2. Symmetric Multiprocessing -each processor performs all tasks
Time sharing (multitasking)
A logical extension in which CPU switches jobs so frequently that users can interact with each job while it's running, creating interactive computing
OpenMP
A set of compiler directives as well as an API for programs written in C, C++, or FORTRAN that provides support for parallel programming in shared memory environments.
Multicore processor
A single computing component with 2 or more independent actual processing units.
Starvation
A situation in which processes wait indefinitely within the semaphore
Pipes
Acts as a conduit allowing 2 processes to communicate. System call used for it is pipe(int fd[]) Programming Requirements for a program that uses pipe: 1. Does the pipe allow bidirectional communication or is communication uni-direction? 2. If two way communication is allowed, is it half duplex or full duplex? 3. Must a relationship exist between the communicating processes 4. Can the pipes communicate over a network, or must the communicating processes reside on the same machine?
Advantages and Disadvantages of Peterson's Solution
Advantages - It provides a good algorithmic description of solving the critical section problem and illustrates some of the complexities involved in designing software that addresses the requirements of mutual exclusion, progress and bound waiting Disadvantages - Restricted to two processes that alternate execution between their critical sections and remainder sections
Dual Mode
Allows OS to protect itself and other system components User mode and kernel mode Mode bit provided by hardware Provides ability to distinguish when system is running user code or kernel code
Interprocess Communication
Allows processes to exchange data and information 2 common mechanisms involve shared memory and message passing
Race Condition
An undesirable situation that occurs when a device or system attempts to perform two or more operations at the same time
Asynchronous cancellation vs deferred cancellation
Asynchronous - One thread immediately terminates the target thread Deferred - The target thread periodically checks whether it should terminate, allowing it an opportunity to terminate itself in an orderly fashion.
Blocking vs non blocking receive
Blocking receive - The receiver blocks until a message is available Nonblocking receive - The receiver retrieves either a valid message or a null
Blocking vs non blocking send
Blocking send - The sending process is blocked until the message is received by the receiving process or by the mailbox. Nonblocking send - The sending process sends the message and resumes operation
Bounded vs Unbounded Capacity
Bounded - Queue has a finite length n and at most n messages can reside in it. If the link is full, the sender must block until space is available in the queue. Unbounded - The queue's length is potentially infinite. Thus any number of messages can wait in it. The sender never blocks
Various tasks performed by an Operating System
Control Hardware Access - The operating system provides generic interfaces to services provided by the underlying hardware. Process Management - The OS must allocate resources to processes, enable processes to share and exchange information, protect the resources of each process from other processes and enable synchronization among processes File Management - Type of software that manages data files in a computer system. It has limited capabilities and is designed to manage individual or group files, such as special office documents and records. Memory Management - Process of controlling and coordinating computer memory. Memory management resides in hardware, in the OS (operating system), and in programs and applications.
Counting vs binary semaphore
Counting - Value can range over an unrestricted domain Binary - Value can only range from 0 to 1.
Thread Pools
Create a number of threads at process startup and place them into a pool, where they sit and wait for work
Types of Parallelisms
Data - Focuses on distributing subsets of the same data across multiple computing cores and performing the same operation on each core Task - Involves distributing not data but tasks across multiple computing cores
System Programs
Device Manager Command Prompt File Management Status Information File Modification Communications
Thread Local Storage
Each thread having its own copy of certain data.
DMA (Direct Memory Access)
Feature of computer systems that allows certain hardware subsystems to access main system memory (Random-access memory), independent of the central processing unit (CPU). With DMA, the CPU first initiates the transfer, then it does other operations while the transfer is in progress, and it finally receives an interrupt from the DMA controller when the operation is done.
Multi mode
Virtual machine manager mode for guest VMs
Advantages of Multiprocessor Systems
Increased throughout - The more processors, the more work gets done in less time Economy of Scale - Can cost less than equivalent multiple single processor systems because they can share peripherals, mass storage and power supplies Increased reliability - If 1 processor fails, it won't halt the system as the other processors can pick up a share of the work of the failed processor
Multiprogramming (Batch System)
Increases CPU utilization by organizing jobs so that the CPU always has one to execute Single user cannot keep CPU and I/O devices busy at all times A subset of total jobs in system is kept in memory One job selected and run via job scheduling When it has to wait (for I/O for example), OS switches to another job
The three requirements to the CS Problem
Mutual exclusion - If process P1 is executing in its critical section, then no other processes can be executing in their critical sections Progress - If no process is executing in its critical section and some processes wish to enter their critical sections, then only those processes that are not executing in their remainder sections can participate in deciding which will enter its critical section next, and this selection cannon be postponed indefinitely Bound Waiting - There exists a bound or limit on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted
Explain the two algorithms discussed in class for hardware solution to process synchronization
Mutual exclusion implementation with test_and_set() - Instructions are executed simultaneously , they will be executed sequentially in some arbitrary order. Bound waiting mutual exclusion with test_and_set() - Process pi can only enter its critical section only if either waiting[i] = false or key == false. The variable waiting[i] can become false only if another process leaves its critical section. Only one waiting[i] is set to false, maintaining the mutual exclusion requirement
Process States
New - Process is being created Running - Instructions are being executed Waiting - Process is waiting for some event to occur( such as an I/O completion or reception of a signal) Ready - The process is waiting to be assigned to a processor Terminated - The process has finished execution
What is the role of a timer in an OS?
Prevent infinite loop / process hogging resources Timer is set to interrupt the computer after some time period Keep a counter that is decremented by the physical clock. Operating system set the counter (privileged instruction) When counter zero generate an interrupt Set up before scheduling process to regain control or terminate the program that exceeds the allotted time
Types of System Calls
Process Control - fork() exit() CreateProcess() File Manipulation - open() read() CreateFile() Device Manipulation - read() write() SetConsoleMode() Information Maintenance - getpid() alarm() GetCurrentProcessID() Communication - pipe() shm_open() CreatePipe() Protection - chmod() umask() chown() SetFileSecurity()
Operations on Processes
Process Creation - Creates a new process using fork() Process Termination - Termination of the process when it finishes executing its final statement and asks the operating system to delete it by using the exit() system call
PCB structure
Process state Process number Program counter Registers Memory limits List of open files
Several Acronyms
RAM - Random Access Memory ROM - Read Only Memory EEPROM - Electrically Erasable Programmable Read Only Memory DRAM - Dynamic Random Access Memory PCB - Process Control Block CS - Critical Section DMA - Direct Memory Access IPC - Interprocess Communication CPU - Central Processing Unit
OS services provided for the efficiency of computing system itself
Resource allocation Accounting Protection and Security
Benefits of Multithreaded Programming
Responsiveness - Multi-threading an interactive application may allow a program to continue running even if part of it is blocked or is performing a lengthy operation, thereby increasing responsiveness to the user. Resource Sharing - Threads share the memory and the resources of the process to which they belong by default Economy - It is more economical to create and context-switch threads.
Process Management
Scheduling processes and threads on the CPUs Creating and deleting both user and system processes Suspending and resuming processes Providing mechanisms for process synchronization Providing mechanisms for process communication
Memory picture of running processes in single tasking vs multitasking systems
Single tasking - free memory command interpreter kernel free memory process command interpreter kernel Multitasking - process D free memory process C interpreter process B kernel
Process in Memory
Stack - contains temporary data such as function parameters, return addresses, and local variables heap - memory that is dynamically allocated during process run time. data - contains local variables text - program's code along with the program counter and the contents of the processor's registers.
Micro kernels
Structures the operating system by removing all nonessential components from the kernel and implementing them as system and user level programs
Context Switching
Switching the CPU to another process requires performing a state save of the current process and a state restore of a different process. When it occurs, the kernel saves the context of the old process in its PCB and loads the saved context of the new process scheduled to run.
System call vs API
System calls provide an interface to the services made available by an operating system. Application Programming Interface specifies a set of functions that are available to an application programmer, including the parameters that are passed to each function and the return values the programmer can expect
Virtualization
Technology that allows operating systems to run as applications within other operating systems
Interrupt Driven
The CPU works on its given tasks continuously. When an input is available, such as when someone types a key on the keyboard, then the CPU is interrupted from its work to take care of the input data.
Layered Approach
The operating system is broken into a number of layers. The bottom layer is the hardware, and the highest layer is the user interface. Advantage: Layered approach is simplicity of construction and debugging
System view of an OS
The OS is the program most intimately involved with the hardware from the system's point of view. An OS in this case is a resource allocator (Manager of resources). It can also act as a control program in which it manages the execution of user programs to prevent errors and improper use of the computer.
User view of an OS
The goal is to maximize the work that the user is performing. (Ease of use) A user can be sitting in front of a PC, consisting of a monitor, keyboard, mouse and system unit. They can also be sitting at a terminal connected to a main frame or a minicomputer. In this case, resource utilization must be maximized. (How various hardware and software resources are shared.
Deadlock
The implementation of a semaphore with a waiting queue may result in a situation where 2 or more processes are waiting indefinitely for an event that can be caused by only one of the waiting process. The vent in question is execution of a signal() operation. Example: Po Pi1 wait(S); wait(Q); wait(Q); wait(S); . . . . . . signal(S); signal(Q); signal(Q); signal(S); Suppose that Po executes wait(S) and then P1 executes wait(Q). When Po executes wait(Q), it must wait until P1 executes signal(Q). Similarly, when P1 executes wait(S), it must wait until Po executes signal(S). Since these signal() operations cannot be executed, Po and P1 are deadlocked
Kernel
The one program running at all times on the computer
Zero Capacity
The queue has a max length of 0. Thus the link cannot have any messages waiting in it.
Critical Section
The segment of code that each process has in which the process may be changing some common variables, updating a table, writing a file, and so on.
Threads
The smallest sequence of programmed instructions that can be managed independently by a scheduler
Bootstrap Program
The state where the computer is booting. It checks for the number of disk controllers and usbs connected to the computer.
Mutex
Used to protect critical regions and thus prevent race conditions Operations it provides: Acquire Lock - acquires the lock Release Lock - releases the lock Busy Waiting -While a process is in its critical section, any other process that tries to enter its critical section must loop continuously in the call to acquire(). Spin lock - The process spins while waiting for the lock to become available
User Goals vs System Goals
User Goals - System should be convenient to use, easy to learn and to use, reliable, safe, and fast. System Goals - System should be easy to design, implement, and maintain and it should be flexible, reliable, error free and efficient
OS services provided to the user
User interface Program execution I/O operations File-system manipulation Communications Error Detection
Rendezvous
When both send() and receive() are both blocking
Unix/Linux System Calls
read() - reads from a buffer write() - writes to a buffer open() - opens a file fork() - creates new process
shm_fd() vs ftruncate()
shm_fd() - Used to create a shared memory object ftruncate() - Configures the size of the object in bytes