CPSC351 Midterm - Kinta Okunta
When threads are applied correctly, your application can benefit in a number of ways. In the list below, cross out the two items that are not true benefits. (2 pts) Responsiveness - may allow continued execution if part of process is blocked, especially important for user interfaces Resource Sharing - threads share resources of process, easier than shared memory or message passing Synchronization - unlike shared memory between processes, synchronization is not required when threads share memory Economy - cheaper than process creation, thread switching lower overhead than context switching Isolation - the execution of one thread cannot interfere with the execution of another thread Scalability - process can take advantage of multiprocessor architectures
*Synchronization - unlike shared memory between processes, synchronization is not required when threads share memory *Isolation - the execution of one thread cannot interfere with the execution of another thread
How would a system call be generally implemented?
- A kernel maintains a table of system calls and each system call has a unique ID. - API (run-time support library)
What is dual mode operation?
- Enforced by hardware. Kernel and user processes are separated. - Typically kernel has access to all instructions and all areas of memory. - User usually has limited access to instructions and areas of memory.
What is multiprogramming needed for?
- It is needed for efficiency - Multiprogramming focuses on keeping the CPU busy with at least one job. - When CPU has to wait for a job it makes the CPU switch to another job.
What types of methods are there for parameter passing? Describe each one.
- Pass parameter to registers. - Parameters stored in a block or table in memory -> address of block passed into the register. - Parameters pushed onto stack by program and later popped off the stack by the OS.
What does it mean when an OS is a resource allocator or a control program?
- Resource allocator: means that it manages resources. - Control program: means that it controls the executions of certain programs.
What problems could we encounter if we allow the process to have direct access over a resource? What can help prevent this problem?
- System instability could occur. - Any user could view/modify another users data. - System calls
What is the limitation of passing a parameter to a register? Are the other two limited?
- The number of parameters could exceed number of registers. - No the block method and stack methods do not have any limitations on parameters.
Whats happening here? http://i.imgur.com/CsHYUnX.png
- The user application invokes a system call from the system call interface. - The system call interface handles how the kernel searches for the appropriate system calls. - Kernel looks for the appropriate call in a table and returns it back to the system call interface.
What "layers" are there in an operating system service?
- User and System programs. - Operating system which consists of... 1. GUI, Batch, CMD line, UI. 2. System calls 3. Services: program, .exe,IO, error detection,resource allocation. - Hardware
What is a condition variable?
A condition variable is what enables the process to suspend itself until a condition holds.
What is a deadlock?
A deadlock happens when a process cannot change states because it is waiting indefinitely on an event to be triggered by one of the waiting processes.
What is a job queue?
A job queue are all processes within a system.
What is a kernel?
A kernel is a program that runs at all times.
What is used as an intermediary data-structure for the user and kernel threads? What does it do?
A light-weight-process is used as an intermediary between the kernel and user thread. It is a virtual processor on which the application can schedule a user thread to run.
What is a long-term scheduler? How often is it called?
A long-term scheduler selects a process that should be brought into the ready queue. Called less frequently.
What is starvation? How do you solve this problem? (In terms of priority scheduling)
A low-level priority that waits indefinitely. Solve this problem with aging which is gradually increasing the priority of the process that wait in the system for a long time.
What types of execution options are there for a parent and child?
A parent and child can execute concurrently. Parent waits until child terminates.
What is a process and how does it relate to a program? .
A process is an instance of a program that has resources allocated to it. A program that is just data on disk
How do mutexes work? What atomic functions do they use?
A process must acquire a lock before entering the critical section and has to release it after leaving the critical section. Acquire and release are atomic functions.
What is starvation in terms of the semaphore queue? When would this occur?
A process that is never removed from the semaphore queue. This happens if other processes hog the shared resources before the process in the semaphore queue.
We can implement a semaphore with a wait queue, how does it work?
A process waiting in a semaphore queue does not get scheduled to run on a processor. When a semaphore is signaled a process is moved to the ready queue. EXAMPLE: http://i.imgur.com/rmIySWr.png
What is an operating system?
A program that is a intermediary between user and hardware.
What is a monitor?
A programmer created construct that is used to manage semaphores.
What is a race condition?
A race condition is when multiple process modifies/access data concurrently and the result of that highly depends on the order of access/modification.
What is it called when both send and receive are blocking?
A rendezvous occurs.
How does shared memory work?
A segment of memory is allocated, other processes have access to it. The shared area exists until explicitly destroyed.
What is a short-term scheduler? How often is it called?
A short-term scheduler selects what job should be done next and allocates CPU. Called more frequently.
What is a synchronous call? (Blocking)
A synchronous call is when... Blocking send - Sender is blocked until message received. Blocking receive - receiver is blocked until a message is available.
When is a program active or passive?
Active - The program executable is loaded into memory. Passive - The program is stored on the disk.
What is a device queue?
All processes waiting for I/O device.
What does IPC allow processes to do?
Allows the processes to cooperate using shared resources provided by the OS.
What is a two level model?
Allows user level thread to be bound to kernel thread.
What is a thread library? What are the two ways in implementing thread libraries?
An API that is provided to the programmer that helps in creating and managing threads. Two ways are: implementing in user space or at kernel level which is supported by the OS.
What is a ready queue?
Are all processes in main memory ready and waiting to be executed.
What is the shortest job first algorithm?
Associates each process with the length of its next CPU burst. Lengths are used to schd to schedule the process with the shortest time. Can be preemptive or non-preemptive.
What are two types of multiprocessing?
Asymmetric - each processor is assigned a different task. Symmetric - each processor performs all tasks.
What is an asynchronous call? (Non-blocking)
Asynchronous call is when... Non-blocking send - the sender sends a message and continues. Non-blocking receive - the receiver receives a valid message or null message.
TestAndSet and CompareAndSwap are examples of processor operations designed specifically to help programmers with process synchronization. They execute a series of operations as a single non-interruptible operation, which means they are...
Atomic
What two threading models require communication? Why?
Both many-to-many and two-level models require communication. Both models need to maintain the appropriate number of kernel threads in an application.
As a process executes, it alternates between ___ and ___.
CPU Bursts I/O Bursts
What do processes alternate between?
CPU bursts and I/O bursts
What properties of CPU scheduling determines its success?
CPU execution I/O waiting
What concept satisfies the problem of rotating a process off and on a processor?
Context switch concept was created to efficiently suspend and activate a process on a processor.
What problems are there in regards to context switching?
Context switch time is considered overhead because the system does no useful work while switching.
Which two of the following statements are true? A mutex and a counting semaphore are conceptually similar Deadlocks may occur when locking is applied incorrectly by a programmer Process starvation occurs when a process is unable to run because other processes continually claim the resource it is waiting on. Spinlocks are efficient because they prevent waiting processes from running on a processor until the locks are released.
Deadlocks may occur when locking is applied incorrectly by a programmer Process starvation occurs when a process is unable to run because other processes continually claim the resource it is waiting on.
What is a memory mapped file?
Describe how it works. A disk file is mapped to a segment of memory and the file can be shared with other processes. Processes have direct access to it.
What is data parallelism?
Different parts of data is spread across multiple cores and the same operation is performed on it.
What is the round robin scheduling algorithm?
Each process gets a small unit of CPU time called time quantum. When the allotted time has elapse the current process is preempted and added to the ready que.
What is one-to-one?
Each user-level thread is assigned a kernel thread. More concurrency than many-to-one
What is a message queue? Describe how it works.
Enables sending messages from one process to another. System handles the message queue Already synchronized.
What is process synchronization?
Ensures orderly execution of cooperating process that share data, in order to maintain data consistency.
What does process synchronization do?
Ensures that shared data is always handled correctly between other processes. Prevent race conditions.
List the goals that operating systems are designed to achieve?
Execute user programs and make solving user problems easier Make the computer system convenient to use Use the computer hardware in an efficient manner
How do we estimate the CPU burst of a process for shortest job first?
Exponential averaging
The processes listed below are in the ready queue of a first-come-first-serve scheduler. Use this information to answer the following questions. http://i.imgur.com/rdc8wGT.png Draw a gantt chart to show the times and duration each process is active. Calculate the avg waiting time. Situation where the short processes wait behind long processes is called the___
Gantt Chart http://i.imgur.com/JlaYwuy.png (P1wait + P2wait + P3wait + P4wait)/(# processes) = (0 + 8 + 20 + 24) / 4 = 13 Convoy effect
What is the goal of process scheduling? What does is it do?
Goal of process scheduling is to Maximize CPU usage. A process scheduler selects the next task for a CPU.
Give an example of an I/O burst and a CPU burst.
I/O Burst - a process that waits for I/O CPU Burst - store increment index, write to file, load store, add store, read from file etc.
What is interprocess communication (IPC)? Give an example of an IPC method an operating system might provide.
IPC enables processes to share information and send messages to each other. Ordinary Pipes Named Pipes Shared Memory Memory Mapped File Signals Message Queues
What new issues do programmers face with multicore programming?
Identifying activities Balance Data splitting Data dependency Testing and debugging
How does time quantum effect the performance of the RR algorithm?
If the time quantum is very large RR degenerates to a first-come first-serve. If the time quantum is very small then the context switch latency could get in the way making over head too high.
What happens in preemptive priority?
If there is a new process that has highest priority then the scheduler will preempt the current running process on the CPU.
What is implicit threading?
Implicit threading is when the thread management is done by the compilers and run-time libraries instead of the programmer themselves.
What are the advantages of having a multiprocessor?
Increased throughput. Better economically. Increased reliability.
What is a process control block (PCB)? Define all parts of the PCB.
Is information that is associated with each process. Process state - running, waiting, etc. Program counter - location of instruction to execute next. CPU Registers - contents of all process centric registers CPU Scheduling Information - priorities, scheduling queue pointers. Memory management information - memory allocated to the process. Accounting Information - amount of CPU used, clock time elapsed since start, time limits. I/O status information - List of I/O devices allocated to processes, list of open files.
What is CPU scheduling?
Is selecting the next process for execution once the current running process is finished.
What is a system-contention scope?
Is when a kernel that executes a user thread from a process competes for execution on the physical CPU with other kernel threads.
What is a process-contention scope?
Is when a user thread process competes for execution on a LWP or kernel with other threads of the same processes
What are some disadvantages of using the message queue?
It has some overhead because you have to call send/recv system calls. Number of messages are limited.
What is an upcall? What is its main role?
It is a communication mechanism from the kernel to the up call handler in the thread library. An upcall helps maintain the correct number of kernel threads.
What are the pros/cons of shared memory? Is it a good idea to use pointers?
It is considered efficient because of direct access to memory. Do not store pointers in shared memory. CON: You have to synchronize to prevent data corruption.
How are semaphores manipulated?
It is manipulated via atomic operations such as wait() or signal().
What is the purpose of the semaphores?
It protects the critical region. Allows more control. Has binary and counting variants.
What does a CPU scheduler do? Is it long term or short term?
It selects a process from the processes in memory that are ready to execute. CPU is then allocated to the selected process.
What is the many-to-many model? How does this benefit the OS?
Many user level threads mapped to many kernel threads. It lets the OS create a sufficient amount of kernel threads.
What is many-to-one?
Many user-level threads mapped to one kernel. If one thread is blocked then it causes all threads to block.
What is the goal of CPU scheduling?
Maximize the degree of multiprogramming. Have some process run at all times.
What does it mean when an instruction/function is atomic?
Means that those instructions/functions are uninterruptible.
What are the requirements for solving the critical section problem?
Mutual Exclusion - One at a time can only enter critical section. Bounded Waiting - There should always be a limit on when a process is blocked from entering the critical section. Progress - Processes outside the critical section cannot block other processes from entering theirs.
What conditions must hold for a deadlock to happen?
Mutual Exclusion: resources are non-shareable. EX: P1 request resource R from P2 meaning that P1 has to wait on P2 to finish with the resource. Hold and wait: Process is holding a resource but is waiting on more resources that are held by other processes. No preemption: resources cannot be preempted; a resource can only be released voluntarily by a process and until it finishes its task. Circular wait: P1 waits on P2 which waits on P3 which waits on Pn. Waiting on resources.
A complete solution to the critical section problem has to meet three requirements. Name and describe two them for up to two bonus points on this quiz.
Mutual exclusion: only one process may enter a critical section at a time. Progress: no process executing outside of its critical section, may block other processes from entering theirs. Bounded waiting: process cannot be perpetually barred by other processes, from entering its critical section.
On the many-to-one mapping can multiple threads run in parallel?
No because only one thread may be attached to a kernel thread at a time.
What is important about the critical section? (Regarding processes)
No two processes can access the critical section at the same time.
You get an awesome job writing software at Pixel Entertainment, a leading producer of computer animated movies and games. You are tasked with writing a rendering algorithm, and quickly realize that by dividing the processing across multiple threads, you can take advantage of parallelism to reduce rendering times. Refer to this scenario, when answering the following questions: Is this scenario an example of using threads to implement task parallelism? At a meeting with the Product Owner, you learned your program will be bundled with a tablet that is powered by a single processor. Will using multiple threads achieve parallelism on this device? Briefly explain. (2 pts)
No, this is data parallelism. No, multiple processors are required for parallelism.
What is a signal? Describe how it works.
Notifies a process that an event occurred. Signal can originate from kernel or process. When process receives a signal it is interrupted and the signal handler is called.
What solution satisfies the need of atomic properties in synchronization?
OS provides semaphores which is a shared resource that enables synchronization between multiple processes or threads.
What is priority inheritance protocol?
Occurs when a higher priority waits on a lower priority to release a lock then the lower priority is given the same priority as the higher priority. The priority is returned back to normal when the lock is released.
What is cascading termination?
Occurs when all children, grandchildren, etc. are terminated.
How many processes can execute inside a monitor?
Only one process can execute one at a time.
What are the two main things inside the monitor?
Operations Shared data on which the operations operate.
What are operations limited to?(In terms of Monitors)
Operations inside the monitor can only access variables within the monitor.
What are ordinary and named pipes?
Ordinary - Processes other than the one that created do not have access to it. But it's children does. Producer writes to one end and the consumer reads at the other end. Named - can be accessed without parent child relationship. (Bidirectional)
Describe two general methods for passing parameters to the operating system when a system call is invoked.
Pass values by storing them in a register Store values in a table and place the address of the value in a register Push values on to the stack and have the kernel pop them off
What is preemptive scheduling? What about non-preemptive?
Preemptive scheduling is when a process executing on a CPU can be interrupted in order to make way for another process. Non-preemptive scheduling is when a process has to run to completion once it's allocated CPU. Can't be interrupted.
______ is a condition where a lower priority process holds a lock that prevents a higher priority process from acquiring it.
Priority Inversion
What is priority inversion? Give an example.
Priority inversion occurs when a lower priority that holds a lock prevents a higher priority process from obtaining a lock. (Lock is needed to access critical region) EXAMPLE: Meaning that if we have priority L < M < H Given that H waits on L to finish. M the only non-blocking process and is allowed to preempt L L must finish in order to give a lock to H. SOLUTION: If we give higher priority it L this means M cannot preempt L and L can finish executing.
What is priority scheduling?
Priority is assigned to each process and the highest priority goes first. This algorithm can be both preemptive and non-preemptive.
Name the structure the operating system uses to store information about a specific process and identify a piece, or category, of information it contains. Briefly explain the purpose of that information.
Process Control Block (PCB) Process state - running, waiting, etc Program counter - location of instruction to next execute CPU registers - contents of all process-centric registers CPU scheduling information- priorities, scheduling queue pointers Memory-management information - memory allocated to the process Accounting information - CPU used, clock time elapsed since start, time limits I/O status information - I/O devices allocated to process, list of open files
What is message passing?
Processes communicate without shared variables and this communication is established via system calls. In message passing typically the OS handles everything but this also adds to overhead.
What is a system call?
Programming interface that allows user-level processes to request services and resources from the operating system.
What are the pros/cons of shortest job first?
Pros: optimal and gives minimal average waiting time. Cons: difficult to calc length of next CPU request
What is the PROS/CONS of FCFS?
Pros: simple to implement and understand. Cons: Average waiting time is often long, convoy effect, and non-preemptive.
In the software industry, it is common practice for developers to peer review each other's code before it is released into production. While reviewing your colleague's multithreaded code, you notice a spot where multiple threads are manipulating the same variables. You fear this is a race condition. While mentoring the enthusiastic college intern, you share that you spotted a race condition in the code. Your mentee has not taken an operating systems class yet and she doesn't know what a race condition is. Describe what race condition is. After explaining race conditions to your mentee, she says, "I understand now, you are concerned because race conditions only occur when cooperating processes are running in parallel on multiprocessor systems, like the servers that run our software." Is she correct? Explain. You share your discovery with your colleague. It turns out she accidentally sent you an earlier version of her code. In the newer version, the code you are concerned about is now sandwiched between calls that acquire and release a mutual exclusion (mutex) lock. Explain why you are satisfied this change fixes the race condition.
Race condition: when multiple processes (or threads) access and manipulate the same data concurrently and the outcome of the execution depends on the particular order in which the access takes place. No, concurrent on processing of two processes on a single processor may still result in race conditions. The mutex guards a critical section, which by definition only allows one process at a time to manipulate the data within it. This ensures that the operations modifying the data are executed in the proper sequence.
What are some benefits of threading or multithreading?
Responsiveness - Continued execution if part of a process is blocked. Resource Sharing - Threads already share some resources from the processes. Economy - Less overhead than creating another process. Scalability - Process can take advantage of multicore processing.
What are the two fundamental models of inter-process communication (IPC). Briefly describe the attributes of each model.
Shared Memory - direct access, low overhead, requires synchronization Message Passing - accomplished using system calls, greater overhead, has synchronization
In a multithreaded process what is shared and what is not shared? DIAGRAM: http://i.imgur.com/o7iJSAz.png
Shared: code, data, files Not shared: registers, stack
What is the convoy effect?
Short process waits behind the long process.
What needs to be scheduled in the multilevel queue algorithm?
Since the ready queue is partitioned into separate queue this means that the set of all queues that's been separated need to be scheduled themselves.
What are the different sections of data in a process?
Stack - temporary data, function parameters, return addresses, local variables. Heap - Dynamically allocated memory at runtime. Program counter Data section - global variables. Text section - program code.
Within a multithreaded process, some of the process' resources are shared by all of the threads. Circle the resources that are exclusive to each thread. Register values Heap Memory Code Stack memory
Stack memory Register values
What is a background service or daemon? How does it differ from a standard system program?
Starts at OS -> start without user intervention, runs continuously, not attached to an user.
What is concurrency?
Supports more than one task making progress.
What is the purpose of system calls?
System calls allow user-level processes to request services from the operating system.
What is multitasking?
The CPU switches jobs so frequently that the user is able to interact with each job while it is running.
Which models schedule the user thread to run on a lightweight process?
The M:M and M:1 models thread library schedules the user thread to run on a light-weight process.
In a resource allocation graph what condition must occur for there to be no deadlocks?
The R.A.G. should contain no cycles so that no deadlocks are possible.
Where is the context of the process stored in?
The context of a process is stored in a process control block.
In the system call signature provided below, which parameter specifies the file it will read from? Explain what the parameter represents. http://i.imgur.com/C0lT3Gu.png
The first parameter is the file descriptor. It is the resource file that the OS is using.
What is the main goal of CPU scheduling algorithms?
The goal of CPU scheduling is to maximize the degree of multi-programming i.e., having some process running at all times.
What helps in facilitating the orderly acquisition of finite resources when using multiple processes?
The operating system implements queues so that a process can wait in to gain access to resources.
What is a critical section?
The part of a code in which a process modifies shared resources.
Which of the following statements about schedulers are true? Round-robin degrades to first-come first-served when the time quantum is too small The preemptive version of shortest-job-first-scheduling is called shortest remaining-time-first. Exponential averaging is used to estimate the optimum time quantum for round robin schedulers. Priority-scheduling may result in low priority processes having to wait indefinitely for processor time.
The preemptive version of shortest-job-first-scheduling is called shortest remaining-time-first. Priority-scheduling may result in low priority processes having to wait indefinitely for processor time.
What is the purpose of a medium-term scheduler? What does it do?
The purpose a medium term scheduler is to reduce the degree of multiprogramming. Swapping: Removes process from memory -> stores onto disk -> brings back from disk and continues execution.
What is the multilevel queue algorithm? What's different about the queues?
The ready queue is partitioned into separate queues. Processes are permanently assigned to the queues based on the property of the processes (memory size, priority, or type) Each queue has different scheduling algorithms.
What occurs during a context switch? What does it accomplish for the operating system?
The state of the active process is saved and the state of another process is restored to become active. The switch time is overhead because CPU does no work while it is in transition. It enables the operating system to do multi-programming/time-sharing/multitasking.
What is parallelism?
The system can perform more than one task simultaneously.
What general problem would a typical OS system solve for the user?
The user has computing hardware and wants that hardware to produce a value for them.
How long do each process wait for in the RR algorithm?
They wait no longer than (n - 1) * q time units.
What can you observe from this picture? (Semaphore implementation) http://i.imgur.com/gxhtqBD.png
This code is constantly polling S in a loop. This also is a implementation of a spinlock. This implementation is called busy waiting and is only good if the critical region is short.
Refer to this diagram when answering the following questions: http://i.imgur.com/5zkQKjt.png What threading model is this? In this model, if a user thread makes a blocking system call, are the other user threads able to do work while the system call is in progress? Briefly explain.
This is a diagram of the many-to-one model. No, they all share the same kernel thread, which makes the program single threaded from the operating system's perspective. No other work will get done until the system call returns.
What helps bridge the implementation of threads at a kernel and user level?
Thread libraries.
What are thread pools? What type of threading are thread pools? What are the advantages?
Thread pools are pre-created number of threads that wait for work. Thread pools are a method of implicit threading. Advantages: save time from creating a thread on the spot, allows # of threads to be bounded to the size of the pool.
What do threads allow?
Threads allow multiple thread executions to operate on a single process.
What is task parallelism?
Threads are spread across cores and each thread does different operations.
How does an operating system maximize utilization of processors while maintaining user performance expectations?
Use flexible algorithms that balance the need of different workloads and users.
What two threads are scheduled different?
User level and kernel threads are scheduled differently
What are user threads? Kernel threads?
User threads: management done by user thread libraries. Kernel threads: Supported by the kernel.
What two operations does a condition variable support?
Wait() - makes the calling process suspend itself. Signal() - resumes a process that has previously called wait.
Allowing only one process at a time is too restrictive what can we do?
We can allow the process suspend itself in the monitor and allow another process to run in the monitor.
What are some options for handling deadlock?
We can try to make it so that a system will never enter a deadlock state. We can allow the system to enter a deadlock then we detect the deadlock and fix it. Or we can pretend that deadlocks will never happen and leave it to developers to write deadlock free applications.
What is the first come first serve algorithm?
Whatever process request the CPU first gets it.
When do CPU scheduling decisions occur? Which conditions are non-preemptive?
When a process switches from... Running to waiting. Running to ready. Waiting to ready. Or when it terminates. All conditions are non-preemptive.
What is as zombie? What is an orphan?
Zombie - occurs when a process terminates but its parent did not call wait(). Orphan - Occurs when a parent did not call wait() and terminates itself.