Operating Systems Exam 1

Ace your homework & exams now with Quizwiz!

How does the signal() operation associated with monitors differ from the corresponding operation defined for semaphores?

5.29. The signal () operation associated with monitor a is not persistent in the following sense: if a signal is performed and if there are no waiting threads, then the signal is simply ignored and the system does not remember that the signal took place. If a subsequent wait operation is performed, then the corresponding thread simply blocks. In semaphores, on the other hand, every signal results in a corresponding increment of the semaphore value even if there are no waiting threads. A future wait operation would immediately succeed because of the earlier increment.

What is the meaning of the term busy waiting? What other kinds of waiting are there in an operating system? Can busy waiting be avoided altogether? Explain your answer.

5.3. Busy it'aiting means that a process is waiting for a condition to be satisfied in a tight loop without relinquishing the processor. Alternatively, a process could wait by relinquishing the processor, and block on a condition and wait to be awakened at some appropriate time in the future. Busy waiting can be avoided but incurs the overhead associated with putting a process to sleep and having to wake it up when the appropriate program state is reached.

5.32 A file is to be shared among different processes, each of which has a unique number. The file can be accessed simultaneously by several processes, subject to the following constraint: the sum of all unique numbers associated with all the processes currently accessing the file must be less than n. Write a monitor to coordinate access to the file.

5.32. The pseudocode is as follows: monitor file access I mt curr sun = 0; mt n; condition c; void access file(int my num) I while (curt sum + my nun >= n) c.wait; curr sun += my num; void finish access(int my nun) curt sun = my nun; c . broadcast O;

a. Identify the data involved in the race condition. b. Identify the location (or locations) in the code where the race condition occurs.

5.37. • Identify the data involved in the race condition: The variable available resources. • Identify the location (or locations) in the code where the race condition occurs: The code that decrements available resources and the code that increments available resources sre the statements that could be involved in race conditions. • Using s semaphore, (ix the race condition: Use s semaphore to represent the svsilablc resources variable and replace increment and decrement operations by semaphore increment snd semaphore decrement operations.

Explain why spinlocks are not appropriate for single-processor systems yet are often used in multiprocessor systems.

5.4. Spinlocks are not appropriate for single-processor systems because the condition that would break a process Out of the spinlock can be obtained only by executing a different process. If the process is not relinquishing the processor, other processes do not get the opportunity to set the program condition required for the first process to make progress. In a multiprocessor system, other processes execute on other processors and thereby modif' the program state in order to release the first process from the spinlock.

6.10 Why is it important for the scheduler to distinguishI/O-bound programs from CPU-bound programs?

6.10. 1/0-bound programs have the property of performing only a small amount of computation before performing 110. Such programs typically do not use up their entire CPU quantum. CPU-bound programs, on the other hand, use their entire quantum without performing any blocking 110 operations. Consequently, one could make better use of the computer's resources by giving higher priority to [/0-bound programs and allow them to execute ahead of the CPU-bound programs.

Using the program shown in Figure 3.30, explain what the output will be at LINE A.

3.1. The result is stillS as the child updates its copy of value. When control returns to the parent, its value remains at5.

What are the benefits and the disadvantages of each of the following? Consider both the system level and the programmer level. a. Synchronous and asynchronous communication b. Automatic and explicit buffering c. Send by copy and send by reference d. Fixed-sized and variable-sized messages

3.18. a) Synchronous and asynchronous communication—A benefit of synchronous communication is that it allows a rendezvous between the sender and receiver. A disadvantage of a blocking send is that a rendezvous may not be required and the message could be delivered asynchronously. As a result, message-passing systems often provide both forms of synchronization. b) Automatic and explicit buffering—Automatic buffering provides a queue with indefinite length, thus ensuring the sender will never have to block while waiting to copy a message. There are no specifications on how automatic buffering will be provided; one scheme may reserve sufficiently large memory where much of the memory is wasted. Explicit buffering specifies how large the buffer is. In this situation, the sender may be blocked while waiting for available space in the queue. However, it is less likely that memory will be wasted with explicit buffering. c) Send by copy and send by reference—Send by copy does not allow the receiver to alter the state of the parameter; send by reference does allow it. A benefit of send by reference is that it allows the programmer to write a distributed version of a centralized application. Java's RMI provides both; however, passing a parameter by reference requires declaring the parameter as a remote object as well. d) Fixed-sized and variable-sized messages—The implications of this are mostly related to buffering issues; with fixed-size messages, a buffer with a specific size can hold a known number of messages. The number of variable-sized messages that can be held by such a buffer is unknown. Consider how Windows 2000 handles this situation: with fixed-sized messages (anything <256 bytes), the messages are copied from the address space of the sender to the address space of the receiving process. Larger messages (i.e. variable- sized messages) use shared memory to pass the message.

Including the initial parent process, how many processes are created by the program shown in Figure 3.31?

3.2. 8 processes are created. The program online includes printf () statements to better understand how many processes have been created.

Describe the actions taken by a kernel to context-switch between processes.

3.9. In general, the operating system must save the state of the currently running process and restore the state of the process scheduled to be run next. Saving the state of a process typically includes the values of all the CPU registers in addition to memory allocation. Context switches must also perform many architecture-specific operations, including flushing data and instruction caches.

Provide two programming examples in which multithreading does not provide better performance than a single-threaded solution.

4.6. 1) Any kind of sequential program is not a good candidate to be threaded. An example of this is a program that calculates an individual tax return. 2) Another example is a "shell" program such as the C-shell or Korn shell. Such a program must closely monitor its own working space such as open files, environment variables, and current working directory.

Under what circumstances does a multithreaded solution using multiple kernel threads provide better performance than a single-threaded solution on a single-processor system?

4.7. When a kernel thread suffers a page fault, another kernel thread can be switched in to use the interleaving time in a useful manner. A single-threaded process, on the other hand, will not be capable of performing useful work when a page fault takes place. Therefore, in scenarios where a program might suffer from frequent page faults or has to wait for other system events, a multithreaded solution would perform better even on a single processor system.

4.8 Which of the following components of program state are shared across threads in a multithreaded process? a. Register values b. Heap memory c. Global variables d. Stack memory

4.8. The threads of a multithreaded process share heap memory and global variables. Each thread has its separate set of register values and a separate stack.

Explain why implementing synchronization primitives by disabling interrupts is not appropriate in a single-processor system if the synchronization primitives are to be used in user-level programs. do { flag[i] = true; while (flag[j]) { if (turn == j) { flag[i] = false; while (turn == j) flag[i] = true; } } /* critical section */ turn = j; flag[i] = false; /* remainder section */ } while (true); ; /* do nothing */

5.10. If a user-level program is given the ability to disable interrupts, then it can disable the timer interrupt and prevent context switching from taking place, thereby allowing it to use the processor without letting other processes execute.

5.11 Explain why interrupts are not appropriate for implementing synchronization primitives in multiprocessor systems.

5.11. Interrupts are not sufficient in multiprocessor systems since disabling interrupts only prevents other processes from executing on the processor in which interrupts were disabled; there are no limitations on what processes could be executing on other processors and therefore the process disabling interrupts cannot guarantee mutually exclusive access to program state.

5.23 Show how to implement the wait() and signal() semaphore operations in multiprocessor environments using the test and set() instruction. The solution should exhibit minimal busy waiting.

5.23. Here is the pseudocode for implementing the operations: mt guard = 0; mt semaphore value wait() while lTesUmdSet(&guard) == 1); if (semaphore value == 0) atomically add process to a queue of processes waiting for the semaphore and set guard to 0; )else semaphore value; guard = 0; signal() while (TestAndSet(&guard) == 1); if (semaphore value == O && there is a process on the wait queue) wake up the first process in the queue of waiting processes else semaphore value++; guard = 0;

Discuss the tradeoff between fairness and throughput of operations in the readers-writers problem. Propose a method for solving the readers-writers problem without causing starvation.

5.28. Throughput in the readers-writers problem is increased by favoring multiple readers as opposed to allowing a single writer to exclusively access the shared values. On the other hand, favoring readers could result in starvation for writprs. The starvation in the readers/writers problem could be avoided by keeping timestamps associated with waiting processes. When a writer is finished with its task, it would wake up the precess that has been waiting for the longest duration. When a reader arrives and notices that another reader is accessing the database, then it would enter the critical section only if there are not waiting waiters. These restrictions would guarantee fairness.

What is the difference between blocking and non-blocking operations?

Blocking : The completion of the call is dependent on certain events. (used with synchronous communication) Non-Blocking: The call returns without waiting for any event to complete (used with asynchronous communication)

What does thrashing stand for?

CPU is mostly context switching

Why are threads better than processes?

They take less time and space to create. They provide faster communication through shared memory instead of IPC.

How do threads communicate?

Through shared resources

What does TDM stand for?

Time-Division Multiplexing. Many virtual CPUs by rotating control of physical CPU

What is Moore's law?

Transistors per chip doubles approximately every 18 months since 1965

What are the four things that we need an operating system to have?

Usability and portability Efficiency Control Isolation

What is starvation?

When one process waits indefinitely for the resources to complete its task, which are repeatedly allocated to other processes.

What is a safe state?

When there is some scheduling order in which every process can run to completion even if all of them request their maximum number of units immediately.

Do threads share resources?

Yes

How do you eliminate no preemption?

1. Preempt requestor resource 2. Preempt holder resource This only works for some resouces

Give two reasons why caches are useful. What problems do they solve? What problems do they cause? If a cache can be made as large as the device for which it is caching (for instance, a cache as large as a disk), why not make it that large and eliminate the device?

1.10. Caches are useful when two or more components need to exchange data, and the components perform transfers at differing speeds. Caches solve the transfer problem by providing a buffer of intermediate speed between the components. If the fast device finds the data it needs in the cache, it need not wait for the slower device. The data in the cache must be kept consistent with the data in the components. If a component has a data value change, and the datum is also in the cache, the cache must also be updated. This is especially a problem on multiprocessor systems where more than one process may be accessing a datum. A component may be eliminated by an equal-sized cache, but only if: (a) the cache and the component have equivalent state-saving capacity (that is, if the component retains its data when electricity is removed, the cache must retain data as well), and (b) the cache is affordable, because faster storage tends to be more expensive.

In a multiprogramming and time-sharing environment, several users share the system simultaneously. This situation can result in various security problems. a. What are two such problems? b. Can we ensure the same degree of security in a time-shared machine as in a dedicated machine? Explain your answer.

1.12. a) Stealing or copying one's programs or data; using system resources (CPU, memory, disk space, peripherals)without proper accounting. b) Probably not, since any protection scheme devised by humans can inevitably be broken by a human, and the more complex the scheme, the more difficult it is to feel confident of its correct implementation.

Direct memory access is used for high-speed I/O devices in order to avoid increasing the CPU's execution load. a. How does the CPU interface with the device to coordinate the b. How does the CPU know when the memory operations are complete? c. The CPU is allowed to execute other programs while the DMA transfer controller is transferring data. Does this process interfere with the execution of the user programs? If so, describe what forms of interference are caused.

1.20. Symmetric multiprocessing treats all processors as equals, and i/O can be processed on any CPU. Asymmetric multiprocessing has one master CPU and the remainder CPUS are slaves. The master distributes tasks among the slaves, and i/O is usually done by the master only. Multiprocessors can save money by not duplicating power supplies, housings, and peripherals. They can execute programs more quickly and can have increased reliability. They are also more complex in both hardware and software than uniprocessor systems.

Consider anSMP system similar to the one shown in Figure 1.6. Illustrate with an example how data residing in memory could in fact have a different value in each of the local caches.

1.23. Say processor 1 reads data A with value 5 from main memory into its local cache. Similarly, processor 2 reads data A into its local cache as well. Processor 1 then updates A to 10. However, since A resides in processor l's local cache, the update only occurs there and not in the local cache for processor 2.

Which of the following instructions should be privileged?. a.Set value of timer. b. Read the clock. c. Clear memory. d. Issue a trap instruction. e. Turn off interrupts. f. Modify entries in device-status table. g. Switch from user to kernel mode. h. Access I/O device

1.6. The following operations need to be privileged: a) set value of timer, b) clear memory, e) turn off interrupts, f) modify entries in device-status table, g) switch from user to kernel mode, h) access I/O device. The rest can be performed in user mode.

What is the purpose of system calls?

2.1. System calls allow user-level processes to request services of the operating system.

Describe three general methods for passing parameters to the operating system.

2.13. a) Pass parameters in registers b) Registers pass starting addresses of blocks of parameters

What is the purpose of the command interpreter? Why is it usually separate from the kernel?

2.5. It reads commands from the user or from a file of commands and executes them, usually by turning them into one or more system calls. It is usually not part of the kernel since the command interpreter is subject to changes.

What is the main advantage of the layered approach to system design? What are the disadvantages of the layered approach?

2.8. As in all cases of modular design, designing an operating system in a modular way has several advantages. The system is easier to debug and modify because changes affect only limited sections of the system rather than touching all sections of the operating system. Information is kept only where it is needed and is accessible only within a defined and restricted area, so any bugs affecting that data must be limited to a specific module or layer.

Discuss how the following pairs of scheduling criteria conflict in certain settings. a. CPU utilization and response time b. Average turnaround time and maximum waiting time c. I/O device utilization and CPU utilization

6.11. a) CPU utilization and response time: CPU utilization is increased if the overheads associated with context switching is minimized. The context switching overheads could be lowered by performing context switches infrequently. This could, however, result in increasing the response time for processes. b) Average turnaround time and maximum waiting time: Average turnaround time is minimized by executing the shortest tasks first. Such a scheduling policy could, however, starve long-running tasks and thereby increase their waiting time. c) 1/0 device utilization and CPU utilization: CPU utilization is maximized by running long-running CPU-bound tasks without performing context switches. 110 device utilization is maximized by scheduling 1/0-bound jobs as soon as they become ready to run, thereby incurring the overheads of context switches.

6.14 Consider the exponential average formula used to predict the length of the next CPU burst. What are the implications of assigning the following values to the parameters used by the algorithm? a. a = 0 and t = 100 milliseconds b. a = 0.99 and t= 10 milliseconds

6.14. When a = O and t0 100 milliseconds, the formula always makes a prediction of 100 milliseconds for the next CPU burst. When a = 0.99 and t0 = 10 milliseconds, the most recent behavior of the process is given much higher weight than the past history associated with the process. Consequently, the scheduling algorithm is almost memoryless, and simply predicts the length of the previous burst for the next quantum of CPU execution.

Consider the following set of processes, with the length of the CPU burst given in milliseconds: Process Burst Time Priority P1 2 2 P2 1 1 P3 8 4 P4 4 2 P5 5 3 The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0. a. Draw four Gantt charts that illustrate the execution of these processes using the following scheduling algorithms: FCFS, SJF, nonpreemptive priority (a larger priority number implies a higher priority), and RR (quantum = 2). b. What is the turnaround time of each process for each of the scheduling algorithms in part a? c. What is the waiting time of each process for each of these scheduling algorithms? d. Which of the algorithms results in the minimum average waiting time (over all processes)?

6.16. a) The four Gantt charts are 112 3 4 I 5 FCFS 21 1 4 I 5 I 3 SJF 3 5 1 4 I 2 Priority 1 2 3 4 5 3 I 4 7 I 3 5 3 RR 1 2 3 41 5 61 7 81 9J 1O 11 121 13J 141 151 I( 17 18 191 20 b) Turnaround time FCFS SJF Priority RR P1 2 3 15 2 P2 3 1 20 3 P3 11 20 8 20 P4 15 7 19 13 P5 20 12 13 18 e) Waiting time FCFS SJF Priority RR Pl 0 1 13 0 P2 2 0 19 2 P3 3 12 0 12 P4 11 3 15 9 P5 15 7 8 15 d) Shortest job first

Consider a system running ten I/O-bound tasks and one CPU-bound task. Assume that the I/O-bound tasks issue an I/O operation once for every millisecond of CPU computing and that each I/O operation takes 10 milliseconds to complete. Also assume that the context-switching overhead is 0.1 millisecond and that all processes are long-running tasks. Describe the CPU utilization for a round-robin scheduler when: a. The time quantum is 1 millisecond b. The time quantum is 10 milliseconds

6.21. a) The time quantum is lmillisecond: Irrespective of which process is scheduled, the scheduler incurs a 0.1 millisecond context-switching cost for every context-switch. This results in a CPU utilization of 1/1.1 * 100 = 91%. b) The time quantum is 10 milliseconds: The 110-bound tasks incur a context switch after using up only I millisecond of the time quantum. The time required to cycle through all the processes is therefore 10*1.1 + 10.1 (as each I/O-bound task executes for 1 millisecond and then incur the context switch task, whereas the CPU-bound task executes for 10 milliseconds before incurring a context switch). The CPU utilization is therefore 20/21.1 * 100 = 94%.

What is circular wait?

A chain of processes exists, such that each process holds at least one resource needed by the next process in the chain.

What are thread pools?

A fixed size set of threads at startup A new request will get thread from the pool That thread is then returned upon request completion If no threads are in the pool, then the request must wait.

What is hold and wait?

A process may hold allocated resources while awaiting assignment of others

What is a cooperating process?

A process that can affect or be affected by the execution of another process.

What is an independent process?

A process that cannot affect or be affected by the execution of another process.

What is a process?

A program in execution

What is race condition?

A race condition occurs when a programmer incorrectly assumed that a particular event would always happen before another.

What is a system call?

A request from the OS.

What is a trap?

A software-generated interrupt, either by error or requested

How do you eliminate circular wait?

Idea: Eliminate the possibility of a cycle 1. Only one resource at a time Problem: Limited 2. Impose global ordering Problem: inefficient and no order will satisfy everyone

How do you eliminate mutual exclusion?

Idea: Make no resource mutually exclusive. Make resource sharable Problem: Some resources are nonsharable

How do you eliminate hold and wait?

Idea: When a process requests a resource, it doesn't hold any others Two Approaches: 1. Atomically acquire all resources at once Problem: could have starvation and poor utilization 2. Only request resources when it does not hold other resources; releasing resources before requesting new ones. Problem: Inefficient and starvation

What are all of the parts of a resource-allocation graph?

Look this up in power point slides

What are the 4 necessary conditions for Deadlock to occur?

Mutual Exclusion Hold and wait No preemption Circular wait

What are the states that a process can change into?

New: The process is being created Running: Instructions are being executed Ready: The process is waiting to be assigned to a processor Terminated: The process has finished execution Waiting: The process is waiting for some event to occur

What is an Interrupt?

Notification of some hardware or software event

What is mutual exclusion?

Only one process may use a resource at a time

What are the two types of resources?

Preemptable - Can be taken away Non-preemptable - Cannot be taken away

What is no preemption?

Previously granted resources may not be taken away

Who owns threads?

Processes

What is Joy's Law?

Processing power of single chip doubles every 18 months

Why can a process change state?

Program action (system call) OS action (scheduling decision) External action (interrupts)

What is deadlock?

Set of processes where each is waiting for an event that only another process in the set can cause. It causes permanent blocking of multiple processes

What does SDM stand for?

Space-Division Multiplexing. Many virtual address spaces by carving out ranges of physical address space.

How does the distinction between kernel mode and user mode function as a rudimentary form of protection system?

The distinction between kernel mode and user mode provides a rudimentary form of protection in the following manner: Certain instructions could be executed only when the CPU is in kernel mode. Similarly, hardware devices could be accessed only when the program is executing in kernel mode. Control over when interrupts could be enabled or disabled is also possible only when the COU is in kernel mode. Consequently, the CPU has limited capability when executing in user mode, thereby enforcing protection of resources.

How are interrupts handled?

The execution is immediately transfered to the handler. Once the handler completes, the interrupted task resumes where it left off.

What is the main difficulty that a programmer must overcome in writing an operating system for a real-time environment?

The main difficulty is keeping the operating system within the fixed time constraints of a real-time system. If the system does not complete a task in a certain time frame, it may cause a breakdown of the entire system it is running. Therefore when writing an operating system for a real-time system, write must be sure that his scheduling schemes don't allow response time to exceed the time constraint.

How does synchronous communication work?

The sender does not return until the matching receive has been posted at the destination process.

How does asynchronous communication work?

There is no coordination between sender and receiver, a message can be sent or received at any time without waiting for the receiver program to receive.


Related study sets

life Policy Provisions & Options

View Set

Saunders: Pharmacology/Cardiovascular

View Set

Unit 8 Quiz (The Reproductive System)

View Set

CH 39 EAQ Management of Nutritional Problems

View Set