OS COSI 131 QUIZ1
Provide two programming examples in which multithreading provides better performance than a single-threaded solution
(1) A web server that services each request in a separate thread. (2) A parallelized application such as a matrix multiplication where different parts of the matrix may be worked on in parallel (3) An interactive GUI program such as a debugger where a thread is used to monitor user input, another thread represents the running application, and a third thread monitors performance
What are two differences between user-level threads and kernel-level threads? Under what circumstances is one type better than the other?
(1) User-level threads are unknown by the kernel, whereas the kernel is aware of kernel threads (2) On systems using either M:1 or M:N mapping, user threads are scheduled by the thread library and the kernel schedules kernel threads (3) Kernel threads need not be associated with a process whereas every user thread belongs to a process. Kernel threads are generally more expensive to maintain than user threads as they must be represented with a kernel data structure.
What are the three major activities of an operating system in regard to secondary-storage management?
(A) Free-space management (b) Storage Allocation (c) Disk scheduling
List the four steps that are necessary to run a program on a completely dedicated machine
(A) Reserve machine time (B) Manually load program into memory (C) Load starting address and begin execution (D) Monitor and Control execution of program from console
What are the three main purposes of an operating system?
1) To provide an environment for a computer user to execute programs on computer hardware in a convenient and efficient manner 2) To allocate the separate resources of the computer as needed to solve the problem given. The allocation process should be as fair and efficient as possible. 3) As a control program it serves two major functions: (a) supervision of the execution of user programs to prevent errors and improper use of the computer, and (b) management of the operation and control of I/O devices
A computer system
A four-part system consisting of (a) hardware, (b) the operating system, (c) the application programs, and (d) the users
Timers could be used to compute the current time. Provide a short description of how this could be accomplished
A program could use the following approach to compute the current time using timer interrupts. The program could set a timer for some time in the future and go to sleep. When it is awakened by the interrupt, it could update its local state, which it is using to keep track of the number of interrupts it has received thus far. It could then repeat this process of continually setting timer interrupts and updating its local state when the interrupts are actually raised.
Operating System
A program that manages the computer hardware.
hardware
A three-part system (a) consisting of the central processing unit (CPU), (b) the memory, and (c) input/output (I/O) devices.
Palm OS provides no means of concurrent processing. Discuss three complications that concurrent processing adds to an operating system
A. A method of time sharing must be implemented to allow each of several processes to have access to the system. This method involves the preemption of processes that do not voluntarily give up the CPU (by using a system call, for instance) and the kernel being reentrant (so more than one process may be executing kernel code concurrently). b. Processes and system resources have protections and must be protected from each other. Any given process must be limited in the amount of memory it can use and the operations it can perform on devices like disks. c. Care must be taken in the kernel to prevent deadlocks between processes, so processes aren't waiting for each other's allocated resources
Some CPUs provide for more than two modes of operation. What are two possible uses of these multiple modes?
Although most systems only distinguish between user and kernel modes, some CPUs have supported multiple modes. Multiple modes could be used to provide a finer-grained security policy. For example, rather than distinguishing between just user and kernel mode, you could distinguish between different types of user mode. Perhaps users belonging to the same group could execute each other's code. The machine would go into a specified mode when one of these users was running code. When the machine was in this mode, a member of the group could run code belonging to anyone else in the group. Another possibility would be to provide different distinctions with kernel code. For example, a specific mode could allow USB device drivers to run. This would mean that USB devices could be serviced without having to switch to kernel mode, thereby essentially allowing USB device drivers to run in a quasi-user/kernel mode.
What is the main advantage of the layered approach to system design? What are the disadvantages of using the layered approach?
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 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.
What resources are used when a thread is created? How do they differ from those used when a process is created?
Because a thread is smaller than a process, thread creation typically uses fewer resources than process creation. Creating a process requires allocating a process control block (PCB), a rather large data structure. The PCB includes a memory map, list of open files, and environment variables. Allocating and managing the memory map is typically the most time-consuming activity. Creating either a user or kernel thread involves allocating a small data structure to hold a register set, stack, and priority.
What are the main advantages of the microkernel approach to system design?
Benefits typically include the following (a) adding a new service does not require modifying the kernel, (b) it is more secure as more operations are done in user mode than in kernel mode, and (c) a simpler kernel design and functionality typically results in a more reliable operating system
How could a system be designed to allow a choice of operating systems to boot from? What would the bootstrap program need to do?
Consider a system that would like to run both Windows XP and three different distributions of Linux (eg., RedHat, Debian, and Mandrake). Each operating system will be stored on disk. During system boot-up, a special program (which we will call the boot manager) will determine which operating system to boot into. This means that rather initially booting to an operating system, the boot manager will first run during system startup. It is this boot manager that is responsible for determining which system to bot into. Typically boot managers must be stored at certain locations of the hard disk to be recognized during system startup. Boot managers often provide the user with a selection of systems to boot into; boot managers are also typically designed to boot into a default operating system if no choice is selected by the user.
Describe the actions taken by a kernel to context switch between kernel-level threads
Context switching between kernel threads typically requires saving the value of the CPU registers from the thread being switched out and restoring the CPU registers of the new thread being scheduled.
Why do some systems store the operating system in firmware, and others on disk?
For certain devices, such as handheld PDAs and cellular telephones, a disk with a file system may not be available for the device. In this situation, the operating system must be stored in firmware.
What are the main differences between operating systems for mainframe computers and personal computers?
Generally, operating systems for batch system have simpler requirements than for personal computers. Batch systems do not have to be concerned with interacting with a user as much as a personal computer. As a result, an operating system for a PC must be concerned with response time for an interactive user. Batch systems do not have such requirements. A pure batch system also may have not to handle time sharing, whereas an operating system must switch rapidly between different jobs.
What system calls have to be executed by a command interpreter or shell in order to start a new process?
In Unix systems, a fork system call followed by an exec system call need to be performed to start a new process. The fork call clones the currently executing process, while the exec call overlays a new process based on a different executable over the calling process.
What is the purpose of the command interpreter? Why is it usually separate from the kernel?
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.
Suppose that a scheduling algorithm (at the level of short-term CPU scheduling) favors these processes that have used the least processor time in the recent past. Why will this algorithm favor I/O-bound programs yet not permanently starve CPU-bound programs?
It will favor I/O-bound programs because of the relatively short CPU burst request by them; however, the CPU-bound programs will not starve because the I/O-bound programs will relinquish the CPU relatively to do their I/O
When a process creates a new process using the fork() operation, which of the following state is shared between the process and the child process? a. Stack b. Heap c. Shared memory segments
Only the shared memory segments are shared between the parent process and the newly forked child process. Copies of the stack and the heap are made for the newly created process.
Distinguish between Process Contention Scheduling (PCS) and SCS scheduling
PCS scheduling is done local to the process. It is how the thread library schedules threads into available LWPs. SCS scheduling is the situation where the operating system schedules kernel threads. On systems using either many-to-one or many-to-many, the two scheduling models are fundamentally different. On systems using one-to-one, PCS and SCS are the same.
Consider the various definitions of operating system. Consider whether the operating should include applications such as Web browsers and mail programs. Argue both that it should and it should not, and support your answer.
Point: Applications such as web browsers and email tools are performing an increasingly important role in modern desktop computer systems. To fulfill this role, they should be incorporated as part of the operating system. By doing so, they can provide better performance and better integration with the rest of the system. In addition, these important applications can have the same look-and-feel as the operating system software. Counterpoint: The fundamental role of the operating system is to manage system resources such as the CPU, memory, I/O devices, etc. In addition, its role is to run software applications such as web browsers and email applications. By incorporating such applications into the operating system, we burden the operating system with additional functionality. Such a burden may result in the operating system performing a less-than-satisfactory job at managing system resources. In addition, we increase the size of the operating system thereby increasing the likelihood of system crashes and security violations.
Define the difference between preemptive and nonpreemptive scheduling
Preemptive scheduling allows a process to be interrupted in the midst of its execution, taking the CPU away and allocating it to another process. Nonpreemptive scheduling ensures that a process relinquishes control of the CPU only when it finished with its current CPU burst.
What advantage is there in having a different time-quantum sizes on different levels of a multilevel queueing system?
Processes that need more frequent servicing, for instance, interacting processes such as editors, can be in a queue with a small time quantum. Processes with no need for frequent servicing can be in a queue with a larger quantum, requiring fewer context switches to complete the processing, and thus making more efficient use of the computer.
We have stressed the need for an operating system to make efficient use of the computing hardware. When is it appropriate for the operating system to forsake this principle and to "waste" resources? Why is such a system not really wasteful?
Single-user systems should maximize use of the system for the user. A GUI might "waste" CPU cycles, but it optimizes the user's interaction with the system.
What is the purpose of system calls?
System calls allow user-level processes to request services of the operating system.
What is the purpose of system programs?
System programs can be thought of as bundles of useful system calls. They provide basic functionality to users so that users do not need to write their own programs to solve common problems.
Again considering the RPC mechanism, consider the "exactly once" semantic. Does the algorithm for implementing this semantic executive correctly even if the "ACK" message back to the client is lost due to a network problem? Describe the sequence of messages and whether "exactly once" is still preserved.
The "exactly once" semantics ensure that a remote procedure will be executed exactly once and only once. The general algorithm for ensuring this combines an acknowledgement (ACK) scheme combined with timestamps (or some other incremental counter that allows the server to distinguish between duplicate messages). The general strategy is for the client to send the RPC to the server along with a timestamp. The client will also start a timeout clock. The client will then wait for one of two occurrences: 1. It will receive an ACK from the server indicating that the remote procedure was performed, or (2) it will time out. If the client times out, it assumes the server was unable to perform the remote procedure so the client invokes the RPC a second time, sending a later timestamp. The client may not receive the ACK for one of two reasons: (1) the original RPC was never received by the server, or (2) the RPC was correctly received -- and performed-- by the server but the ACK was lost. In situation (1), the use of ACKs allows the server ultimately to receive and perform the RPC. In situation (2), the server will receive a duplicate so as not to perform the RPC a second time. It is important to note that the server must send a second ACK back to the client to inform the client the RPC has been performed.
The Sun UltraSPARC processor has multiple register sets. Describe the actions of a context switch if the new context is already loaded into one of the register sets. What else must happen if the new context is in memory rather than in a register set and all the register sets are in use?
The CPU current-register-set pointer is changed to point to the set containing the new context, which takes very little time. If the context is in memory, one of the contexts in a register set must be chosen and moved to the memory, and the new context must be loaded from memory into the set. This process takes a little more time than on systems with one set of registers, depending on how a replacement victim is selected.
Is the Internet a LAN or a WAN?
The Internet is a WAN as the various computers are located at geographically different places and are connected by long-distance network links.
Some early computers protected the operating system by placing it in a memory partition that could not be modified by either the user job or the operating system itself. Describe two difficulties that you think could arise with such as scheme.
The data required by the operating system (passwords, access controls, accounting information, and so on) would have to be stored in or passed through unprotected memory and thus be accessible to unauthorized users.
How does the distinction between kernel mode and user mode function as a rudimentary form of protection (security) 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 CPU is in kernel mode. Consequently, the CPU has very limited capability when executing in user mode, thereby enforcing protection of critical resources.
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
The following operations need to be privileged: (a) Set value of timer, (c) clear memory, (e) turn off interrupts, (f) modify entries in device-status table, and h (access I/O device). The rest can be performed in user mode.
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, the writer must be sure that his scheduling schemes don't allow response time to exceed the time constraint.
Assume that a distributed system is susceptible to server failure. What mechanisms would be required to guarantee the "Exactly once" semantics for execution of RPCs?
The server should keep track in stable storage (such as a disk log) information regarding what RPC operations were received, whether they were successfully performed, and the results associated with the operations. When a server crash takes place and a RPC message is received, the server can check whether the RPC had been previously performed and therefore guarantee "exactly once" semantics for the execution of RPCs.
Suppose that the following processes arrive for execution at the times indicated. Each process will run the listed amount of time. In answering the questions, use nonpreemptive scheduling and base all decisions on the information you have the time the decision must be made: Process > Arrival Time > Burst time P1>0.0>8 P2>0.4>4 P3>1.0>1 a. What is the average turnaround time for these processes with the FCFS scheduling algorithm? b. What is the average turnaround time for these processes with the SJF scheduling algorithm? c. The SJF algorithm is supposed to improve performance, but notice that we chose to run process P1 at time 0 because we did not know that two shorted processes would arrive soon. Compute what the average turnaround time will be if the CPU is left idle for the first 1 unit and then SJF scheduling is used. Remeber that processes P1 and P2 are waiting during this idle time, so their waiting time may increase. This algorithm could be known as future-knowledge scheduling.
To find Turn Around Time we use the formula : TAT = CT - AT where TAT is turn around time CT is completion time AT is arrival time a. 10.53 = (8+11.6+12)/3 b. 9.53 = (8+12.6+8)/3 c. 6.86 = (1+5.6+14)/3 Remember that turn around time is finishing time minus arrival time, so you have to subtract the arrival times to compute the turnaround times. FCFS is 11 if you forget to subtract arrival time.
Assume an operating system maps user-level threads to the kernel using the many-to-many model where the mapping is done through the use of LWPs. Furthermore, the system allows program developers to create real-time threads. Is it necessary to bind a real-time thread to an LWP?
Yes, otherwise a user thread may have to compete for an available LWP prior to being actually scheduled. By binding the user thread to an LWP, there is no latency while waiting for an available LWP; the real-time user thread can be scheduled immediately.
Assume an operating system maps user-level threads to the kernel using the many-to-many model and the mapping is done through LWPs. Furthermore, the system allows developers to create real-time threads. Is it necessary to bind a real-time thread to an LWP? Explain
Yes. Timing is crucial to real-time applications. If a thread is marked as real-time but is not bound to an LWP, the thread may have to wait to be attached to an LWP before running. Consider if a real-time thread is running (is attached to an LWP) and then proceeds to block (i.e. must perform I/O, has been preempted by a higher-priority real-time thread, is waiting for a mutual exclusion lock, etc.) While the real-time thread is blocked, the LWP it was attached to has been assigned to another thread. When the real-time thread has been scheduled to run again, it must first wait to be attached to an LWP. By binding an LWP to a real-time thread you are ensuring the thread will be able to run with minimal delay once it is scheduled.
What are the three major activities of an operating system in regard to memory management?
a. Keep track of which parts of memory are currently being used and by whom b. Decide which processes are to be loaded into memory when memory space becomes available c. Allocate and deallocate memory space as needed
List five services provided by an operating system. Explain how each provides convenience to the users. Explain also in which cases it would be impossible for user-level programs to provide these services.
a. Program execution -- The operating system loads the contents (or sections) of a file into memory and begins its execution. A user-level program could not be trusted to properly allocate CPU time. b. I/O operations -- Disks, tapes, serial lines, and other devices must be communicated with at every low level. The user need only specify the device and the operation to perform on it, while the system converts that request into device- or controller-specific commands. User-level programs cannot be trusted to access only devices they should have access to and to access them only when they are otherwise unused. c. File-System manipulation -- There are many details in file creation, deletion, allocation, and naming that users should not have to perform. Blocks of disk space are used by files and must be tracked. Deleting a file requires removing the name file information and freeing the allocated blocks. Protections must also be checked to assure proper file access. User programs could neither ensure adherence to protection methods nor be trusted to allocate only free blocks and deallocate blocks on file deletion. d. Communication -- Message passing between systems requires messages to be turned into packets of information, sent to the network controller, transmitted across a communications medium, and reassembled by the destination system. Packet ordering and data correction must take place. Again, user programs might not coordinate access to the network device, or they might receive packets destined for other processes. e. Error detection -- Error detection occurs at both the hardware and software levels. At the hardware level, all data transfers must be inspected to ensure that data have not been corrupted in transit. All data on media must be checked to be sure they have not changed since they were written to the media. At the software level, media must be checked for data consistency; for instance, whether the number of allocated and unallocated blocks of storage match the total number on the device. There, errors are frequently process-independent (for instance, the corruption of data on a disk), so there must be a global program (the operating system) that handles all types of errors. Also, by having errors processed by the operating system, processes need not contain code to catch and correct all the errors possible on a system.
Many CPU-scheduling algorithms are parameterized. For example, the RR algorithm requires a parameter to indicate the time slice. Multilevel feedback queues require parameters to define the number of queues, the scheduling algorithms for each queue, the criteria used to move processes between queues, and so on. These algorithms are thus really sets of algorithms (for example, the set of RR algorithms for all time slices, and so on). One set of algorithms may include another (for example, the FCFS algorithm is the RR algorithm with an infiinite time quantum. What (if any) reltion holds between the following pairs of sets of algorithms? a. Priority and SJF b. Multilevel feedback queues and FCFS c. Priority and FCFS d. RR and SJF
a. The shortest job has the highest priority b. The lowest level of the MLFQ is FCFS c. FCFS gives the highest priority to the job having been in existence the longest D. None
What are the five major activities of an operating system in regard to process management?
a. the creation and deletion of both user and system processes b. The suspension and resumption of processes c. The provision of mechanisms for process synchronization d. The provision of mechanisms for process communication e. The provision of mechanisms for deadlock handling.
A CPU scheduling algorithm determines an order for the execution of its scheduled processes. Given n processes to be scheduled on one processor, how many possible different schedules are there? Give a formula in terms of n.
n! (n factorial = n x n-1 x n-2 x... x2x1)
Application program examples
word processors, spreadsheets, compilers, and web browsers