Data Caches allow faster access of data (usually the most commonly used data) The main problem
} catch (InterruptedException ie) {
is Cache Coherence - We must always use the most recent value, no matter where it is in storage return; } }} hierarchy (making sure the most recent value from the component is stored in the cache) Modify the code, so thread main interrupts Thread-0 and causes the application to print: Total = 6 (we need to maintain consistency between the copy in the cache with its actual value in the memory Change main to have it start the thread then enter a loop that checks sum till it is 6 then call component. This requires extra checking when writing to memory, etc.) thread.interrupt() As well as these issues interrupt - A signal raised by hardware that the causes CPU immediately transfer to a location Locality principle: Data accessed in clusters and stored together defined in the Vector table. A hardware signal that forces a program counter (PC) change Load policy: Retrieve the data needed plus surrounding data Replacement policy: Choice of cache items to expel when the cache fill Difference between a process and a program - A process is an executing program. It is an active What is the difference between user and kernel mode in the hardware? The user mode does not entity; a program is a passive entity. have access to system level instructions(privileged instructions with automatically trap to the OS) Queues in operating systems - The ready queue and the device status queue are two examples. kernel mode has access to system Operating System - Software that creates an environment so computer can perform useful tasks How are I/O bound different than CPU bound processes? Software that is always resident in memory (kernel) plus a set of utility programs that help the I/O-bound Short CPU bursts between I/O (would be faster if I/O was faster) CPU-bound process Long CPU bursts, little I/O (would be faster if CPU was faster) system administrator configure and manage the system. From hndout2/slide3: Which states did the lab1 queue command never display and why? What is a virtual operating system? Give an example. It never displayed running, new, or waiting. New, because processes are created immediately. In A virtual operating system is one that operates as though it has full access and control to lab1 we couldn't display the Running state because we couldn't display the queue while the batch computer system hardware. Low level software present an interface that mimics that of the was running actual hardware. Why would it be unusual for real time systems to use memory mapping Make a mapping from the states defined in lab1/Process.java to the states shown on algorithms? hndout2/slide3. The overhead associated with memory mapping interferes with the strict time requirements New = idle(not 100% sure), running = running, waiting = wait, terminated = terminated, aborted has associated with real time systems. no equivalent, ready has no equivalent What is a cache? Give an example. Why is state new named idle in the lab A batch may be run multiple times, the second A cache is fast storage that temporarily holds data from slower storage to reduce access time, the processes are not new, but they are also not any of the other states. overhead. An example is main memory that caches data stored on disk. What is the difference between an interrupt and a software trap? What is a difference between synchronous and asynchronous I/O? Based on Notes: Interrupt is generated by hardware, trap is by software An application that waits for I/O to complete executes a synchronous I/O call. An application An interrupt is generated by the hardware and are asynchronous (i.e. they don't happen that starts an I/O operation and then immediately continues executing operates at predictable places in the user code) asynchronously. -A trap is an exception in a user process and are used to invoke kernel routines and are a. Batch Generally have few user accounts, which run relatively few, but relatively long jobs synchronous (so the user code is suspended and continues afterwards). where the output of each job is logged to a file, and these jobs, once started, execute to completion without interruption. In the top image, the running process issued an I/O request. After issuing the request, which b. Time Share Generally have many different users running many different kinds of jobs queue did this process get put on? The device queue for which it requested I/O, e.g., disk, display, simultaneously. Most of the users are running interactive jobs giving frequent inputs, which require audio timely responses. In the bottom image at the time the process enters the wait for an interrupt box: c. Real Time Generally there are no human users. The user is some kind of machinery, usually Is it process running or not? Not running. a combination of input sensors and output devices, where it is critical (often life-threatening) that What state is it in? Waiting. all inputs be captured and processed within a highly constrained timeframe. These systems If it is waiting, it must be on some queue. Which one? It depends on what the process did generally are performing a single very specific task, e.g., controlling a heart pace-maker. during its last CPU burst. If it requested I/O (scenario described in the top image), it is waiting on d. Distributed Generally a system whose processors are themselves computer systems that an I/O queue. If it is waiting for another process to complete, it is likely waiting on a notification communicate with the distributed OS over the network. queue for this process. This situation is not well described in the image. e. Handheld Generally have one human user performing small interactive jobs. These operating systems run smartphones and tablets. Process Control Blocks: What data do they store? Basically register they store the Process State f. Embedded Generally control some mechanical system without direct human users. Real time and ID operating systems are often also embedded systems, though not all embedded systems must be real Process Id - Process State - Scheduling Information - Link to Parent Process PCB - time systems. Link to list of Child PCBs - Saved register data - Allocated resources (file list) - Accounting information - I/O or wait status information - Memory-management data General Purpose: respond quickly time to users Why are they necessary? They let a computer resume a process after its pauses its execution Most operating systems use doubly linked lists instead of singly linked lists. Why do you suppose Parallel execution: When two processes both execute at the same time. True parallel execution is that this is the case? possible only on a multiprocessor system. A doubly linked list may be traversed in either direction, which can speed access to a desired item, How does a single processor system simulate parallel execution? Time sharing the processor so long as you know if the desired item is ahead of or behind the current item. between multiple threads, by using context switches when its time slice expires The java class loader will cause a software failure when the name of a class to run is spelled with a public class SumNumbers extends Thread different case. the batch sequencer will bomb. What did you do to avoid this error? { private static double sum = 0.0; The code processing the add command attempts passes the program name the user gave to the private int upper; Process constructor, which calls Class.forName() passing in this program name. This method public SumNumbers(int upper) throws ClassNotFoundException if a class with this name does not exist. The Process constructor { this.upper = upper; } allowed this exception to propagate to the add method code, which caught the exception and public static void main(String[] args) throws InterruptedException printed an error message. What is the difference between a Java Exception and a Java Error? { SumNumbers thread = new SumNumbers(100); An exception is an object created when a java application has attempted an unexpected operation thread.start(); // set a break here and inside run() and on join() like dereferencing a null reference or attempting to open a file that does not exist. A java error thread.join(); happens when something in the environment in which the Java VM is running goes wrong in an System.out.println("Total = " + sum); } unrecoverable way examples running out of memory or attempting to access memory reserved public void run() for the operating system. The important difference between the two is an application should catch { sum = 0; for (int i=0; i<upper; i++) sum += i; } } and handle exceptions, but it should not attempt to catch or handle errors. When this program runs, how many threads are created by the JVM? Which activities related to process management did we implement in this lab? 2 the main thread and Thread-0 -- the SumNumbers thread Adding a process to the ready queue, - Removing a process from the ready queue, - Requesting a What do these two statements mean? process run at a particular priority level, - Running a list of processes. thread.start(); // set a break here and inside run() and on join() Why are command interpreters separate from the kernel? start causes the thread object to execute, executes run the method of SumNumbers The kernel must manage running processes, of which the command interpreter is only one. The thread.join(); kernel must continue running to service both commands from the user and requests from other join causes the current thread to wait(main) until the thread object (SumNumbers) finishes running processes. executing Which thread executes these statements? Main How could we have implemented our batch system with the command interpreter separate? Which statements does Thread-0 execute? By creating a class for the kernel and running it in a separate thread as we do in lab 2. public void run() In our batch system, what part of it would be considered the kernel? { sum = 0; for (int i=0; i<upper; i++) sum += i; } The portion of the code that processes the commands entered by the user, which includes almost When does Thread-0 stop? When its run() method returns. everything except the code implementing the console. Is Thread-0 aware of Thread main? No. Thread-0 has no reference to main. How did we use polymorphism in this project? Does main hold a reference to Thread-0? Yes, in the variable named thread. Each runnable program was required to be built from a subclass of the abstract class Program. A Can main force Thread-0 to stop? No. Process object then held a variable classInstance of type Program. This polymorphic variable held How could you modify the code, so Thread-0 could be interrupted by Thread main? a reference to objects built from either the Fibonacci, Tower or Primes classes. public void run() { sum = 0; for (int i=0; i<upper; i++) { sum += i; try { Thread.sleep(1000); What are four functions of an operating system? Give a one sentence description of each. Memory management control where processes are in memory Memory protection process cannot overwrite each other's memory File management present a uniform view of files and directories Scheduling Implement algorithms to give processes fair access to the CPU What are the three ways applications pass parameters to operating systems to process system calls? Through registers, through a block of contiguous memory, through a hardware stack What is the storage hierarchy? Give three examples of components in this hierarchy. A group of memory devices with different speeds and efficiencies with the faster ones at the top of the hierarchy. The hardware cache, main memory, and magnetic disks are three components of this hierarchy. Name three policies and mechanisms. process independence memory mapping algorithms fair access to cpu implement appropriate scheduling algorithms support many devices well defined device driver interface What are the functions of each of the three types of schedulers? Short term share CPU control among processes in memory Medium term swap processes between memory and disk Long term control the degree of multiprogramming| Describe in a paragraph how you prevented the operating system from crashing when the user did something illegal. The CLI caught exceptions using Java's try/catch mechanism. These try/catch constructs were as close to the command as possible so the error messages would be appropriate. Failure of dynamic class loading had to catch Throwable objects because of the peculiarity of the forName method. List three user errors that the operating system handled. Adding a program to a batch when no batch exists Attempting to add a non-existent program to a batch Attempt to change priority of a process that doesn't exist. Pseudo code the steps involved in processing an OS system call. Execute the privileged system call instruction Hardware generates a trap The system changes to kernel mode The operating system Saves the environment Indexes the call id to find the correct handler Executes the system call handler The short term scheduler Decides which process should execute System changes to user mode control returns to a user process Pseudo code the steps involved in a context switch. Decide which process should execute next Save the environment associated with the executing process Restore the environment associated with the new process Chance the system to user mode Transfer control to the new process Time constraints - hard(fails if does not meet constraints) soft(best effort) Kernel: The part of the OS that is always in memory Provides a basic interface for programs and device drivers Includes: scheduler, I/O subsystem, Memory Management module, and many others User Interface: Command line interface, shell, or GUI enabling the operating system users to issue commands to the OS. System Programs: System level applications that normally reside on disk. Examples include loaders, compilers, editors, disk utilities, batch systems, communication services, system usage monitors, etc. Operating System Functions Create a secure and stable user-friendly environment Efficiently schedule and execute programs (processes ) Read and write from system hardware devices Connect to local and wide area network Manage memory allocation and protect against illegal access Define and maintain the directory and access to secondary storage Allocate and share resources efficiently and fairly Maintain system security Enforce scheduling priorities Recovery from system faults Perform low-level system services for applications A Multiprocessor environment must provide cache coherency. All CPUs have the most recent value in their local cache Context switches save old process state and load the new process state java threads isAlive() returns if a thread is dead or not, getState() returns one of the states shown (new, runable, blocked, waiting, timed_waiting, teriminated) thread.stop asynchronous cancellation, isInterrupted and interrupted check to see if it is interrupted is preserves signal and interrupted resets it