Operating Systems Homework

Anonymous

Question Description

Do the following problems at the end of Chapter 1 in the textbook: 1,9,10,12,14,28,33
Do the following problems at the end of Chapter 2 in the textbook: 1,3,5,7,15,33,41


I have uploaded the questions for you

Unformatted Attachment Preview

SEC. 1.12 SUMMARY 81 The heart of any operating system is the set of system calls that it can handle. These tell what the operating system really does. For UNIX, we have looked at four groups of system calls. The first group of system calls relates to process creation and termination. The second group is for reading and writing files . The third group is for directory management. The fourth group contains miscellaneous calls. Operating systems can be structured in several ways. The most common ones are as a monolithic system, a hierarchy of layers, microkernel, client-server, virtual machine, or exokernel. PROBLEMS 1. What are the two main functions of an operating system? 2. In Section 1.4, nine different types of operating systems are described. Give a list of applications for each of these systems (one per operating systems type). 3. What is the difference between timesharing and multiprogramming systems? 4. To use cache memory, main memory is divided into cache lines, typically 32 or 64 bytes long. An entire cache line is cached at once. What is the advantage of caching an entire line instead of a single byte or word at a time? 5. On early computers, every byte of data read or written was handled by the CPU (i.e., there was no DMA). What implications does this have for multiprogramming? 6. Instructions related to accessing 1/0 devices are typically privileged instructions, that is, they can be executed in kernel mode but not in user mode. Give a reason why these instructions are privileged. 7. The family-of-computers idea was introduced in the 1960s with the ffiM System/360 mainframes. Is this idea now dead as a doornail or does it live on? 8. One reason GUls were initially slow to be adopted was the cost of the hardware needed to support them. How much video RAM is needed to support a 25-line x 80-row character monochrome text screen? How much for a 1200 X 900-pixe1 24-bit color bitmap? What was the cost of this RAM at 1980 prices ($5/KB)? How much is it now? 9. There are several design goals in building an operating system, for example, resource utilization, timeliness, robustness, and so on. Give an example of two design goals that may contradict one another. 10. What is the difference between kernel and user mode? Explain how having two distinct modes aids in designing an operating system. 11. A 255-GB disk has 65,536 cylinders with 255 sectors per track and 512 bytes per sector. How many platters and heads does this disk have? Assuming an average cylinder seek time of 11 ms, average rotational delay of 7 msec and reading rate of 100MB/sec, calculate the average time it will take to read 400 KB from one sector. 82 INTRODUCTION CHAP. 1 12. Which of the following instructions should be allowed only in kernel mode? (a) Disable all interrupts. (b) Read the time-of-day clock. (c) Set the time-of-day clock. (d) Change the memory map. 13. Consider a system that has two CPUs, each CPU having two threads (hyperthreading). Suppose three programs; PO, Pl, and P2, are started with run times of 5; 10 and 20 msec, respectively. How long will it take to complete the execution of these programs? Assume that all three programs are 100% CPU bound, do not block during execution, and do not change CPUs once assigned. 14. A computer bas a pipeline with four stages. Each stage takes the same time to do its work, namely, 1 nsec. How many instructions per second can this machine execute? 15. Consider a computer system that has cache memory, main memory (RAM) and disk, and an operating system that uses virtual memory. It takes 1 nsec to access a word from the cache, 10 nsec to access a word from the RAM, and 10 ms to access a word from the disk. If the cache hit rate is 95% and main memory hit rate (after a cache miss) is 99%, what is the average time to access a word? 16. When a user program makes a system call to read or write a disk file, it provides an indication of which file it wants, a pointer to the data buffer, and the count. Control is then transferred to the operating system, which calls the appropriate driver. Suppose that the driver starts the disk and terminates until an interrupt occurs. In the case of reading from the disk, obviously the caller will have to be blocked (because there are no data for it). What about the case of writing to the disk? Need the caller be blocked awaiting completion of the disk transfer? 17. What is a trap instruction? Explain its use in operating systems. 18. Why is the process table needed in a timesharing system? Is it also needed in personal computer systems running UNIX or Windows with a single user? 19. Is there any reason why you might want to mount a file system on a nonempty directory? If so, what is it? 20. For each of the following system calls, give a condition that causes it to fail: fork, exe c, and unlink. 21. What type of multiplexing (time, space, or both) can be used for sharing the following resources: CPU, memory, disk, network card, printer, keyboard, and display? 22. Can the count = write (fd, buffer, nbytes); call return any value in count other than nbytes? If so, why? 23. A file whose file descriptor is fd contains the following sequence of bytes: 3, 1, 4, 1, 5, 9, 2, 6 , 5, 3, 5 . The following system calls are made: lseek(fd, 3, SEEK_SED; read(fd, &buffer, 4); CHAP. 1 PROBLEMS 83 where the lseek call makes a seek to byte 3 of the file. What does buffer contain after the read has completed? 24. Suppose that a 10-MB file is stored on a disk Oil! the same track (track 50) in consecutive sectors. The disk arm is currently situated over track number 100. How long will it take to retrieve this file from the disk? Assume that it takes about 1 ms to move the arm from one cylinder to the next and about 5 rns for the sector where the beginning of the file is stored to rotate under the head. Also, assume that reading occurs at a rate of 200MB/s. 25. What is the essential difference between a block special file and a character special file? 26. In the example given in Fig. 1-17, the library procedure is called read and the system call itself is called read. Is it essential that both of these have the same name? If not, which one is more important? 27. Modem operating systems decouple a process address space from the machine's physical memory. List two advantages of this design. 28. To a programmer, a system call looks like any other call to a library procedure. Is it important that a programmer know which library procedures result in system calls? Under what circumstances and why? 29. Figure 1-23 shows that a number of UNIX system calls have no Win32 API equivalents. For each of the calls listed as having no Win32 equivalent, what are the consequences for a programmer of converting a UNIX program to run under Windows? 30. A portable operating system is one that can be ported from one system architecture to another without any modification. Explain why it is infeasible to build an operating system that is completely portable. Describe two high-level layers that you will have in designing an operating system that is highly portable. 31. Explain how separation of policy and mechanism aids in building microkemel-based operating systems. 32. Virtual machines have become very popular for a variety of reasons. Nevertheless, they have some downsides. Name one. 33. Here are some questions for practicing unit conversions: (a) How long is a nanoyear in seconds? (b) Micrometers are often called microns. How long is a megarnicron? (c) How many bytes are there in a 1-PB memory? (d) The mass of the earth is 6000 yottagrams. What is that in kilograms? 34. Write a shell that is similar to Fig. 1-19 but contains enough code that it actually works so you can test it. You might also add some features such as redirection of input and output, pipes, and background jobs. 35. If you have a personal UNIX-like system (Linux, MINIX 3, FreeBSD, etc.) available that you can safely crash and reboot, write a shell script that attempts to create an unlimited number of child processes and observe what happens. Before running the experiment, type sync to the shell to flush the file system buffers to disk to avoid 84 INTRODUCTION CHAP. 1 ruining the file system. You can also do the experiment safely in a virtual machine. Note: Do not try this on a shared system without first getting permission from the system administrator. The consequences will be instantly obvious so you are likely to be caught and sanctions may follow. 36. Examine and try to interpret the contents of a UNIX-like or Windows directory with a tool like the UNIX od program. (Hint: How you do this will depend upon what the OS allows. One trick that may work is to create a directory on a USB stick with one operating system and then read the raw device data using a different operating system that allows such access.) 174 PROCESSES AND THREADS CHAP. 2 PROBLEMS 1. In Fig. 2-2, three process states are shown. In theory, with three states, there could be six transitions, two out of each state. However, only four transitions are shown. Are there any circumstances in which either or both of the missing transitions might occur? 2. Suppose that you were to design an advanced computer architecture that did process switching in hardware, instead of having interrupts. What information would the CPU need? Describe how the hardware process switching might work. 3. On all current computers, at least part of the interrupt handlers are written in assembly language. Why? 4. When an interrupt or a system call transfers control to the operating system, a kernel stack area separate from the stack of the interrupted process is generally used. Why? 5. A computer system has enough room to hold five programs in its main memory. These programs are idle waiting for I/0 half the time. What fraction of the CPU time is wasted? 6. A computer has 4 GB of RAM of which the operating system occupies 512 MB . The processes are all256 MB (for simplicity) and have the same characteristics. If the goal is 99% CPU utilization, what is the maximum I/0 wait that can be tolerated? 7. Multiple jobs can run in parallel and finish faster than if they had run sequentially. Suppose that two jobs, each needing 20 minutes of CPU time, start simultaneously. How long will the last one take to complete if they run sequential! y? How long if they run in parallel? Assume 50% I/0 wait. 8. Consider a multiprogramrned system with degree of 6 (i.e., six programs in memory at the same time). Assume that each process spends 40% of its time waiting for I/0. What will be the CPU utilization? 9. Assume that you are trying to download a large 2-GB file from the Internet. The file is available from a set of mirror servers, each of which can deliver a subset of the file's bytes; assume that a given request specifies the starting and ending bytes of the file . Explain how you might use threads to improve the download time. 10. In the text it was stated that the model of Fig. 2-ll(a) was not suited to a file server using a cache in memory. Why not? Could each process have its own cache? 11. If a multithreaded process forks, a problem occurs if the child gets copies of all the parent's threads. Suppose that one of the original threads was waiting for keyboard input. Now two threads are waiting for keyboard input, one in each process. Does this problem ever occur in single-threaded processes? 12. In Fig. 2-8, a multithreaded Web server is shown. If the only way to read from a file is the normal blocking read system call, do you think user-level threads or kernel-level threads are being used for the Web server? Why? 13. In the text, we described a multithreaded Web server, showing why it is better than a single-threaded server and a finite-state machine server. Are there any circumstances in which a single-threaded server might be better? Give an example. CHAP. 2 PROBLEMS 175 14. In Fig. 2-12 the register set is listed as a per-thread rather than a per-process item. Why? After all, the machine has only one set of :registers. 15. Why would .a thread ever voluntarily give up the CPU by calling thread_yield? After all, since there is no periodic clock interrupt, it may never get the CPU back. 16. Can a thread ever be preempted by a clock interrupt? If so, under what circumstances? If not, why not? 17. In this problem you are to compare reading a file using a single-threaded file server and a multithreaded server. It takes 12 msec to get a request for work, dispatch it, and do the rest of the necessary processing, assuming that the data needed are in the block cache. If a disk operation is needed, as is the case one-third of the time, an additional 75 msec is required, during which time the thread sleeps. How many requests/sec can the server handle if it is single threaded? If it is multithreaded? 18. What is the biggest advantage of implementing threads in user space? What is the biggest disadvantage? 19. In Fig. 2-15 the thread creations and messages printed by the threads are interleaved at random. Is there a way to force the order to be strictly thread 1 created, thread 1 prints message, thread 1 exits, thread 2 created, thread 2 prints message, thread 2 exists, and so on? If so, how? If not, why not? 20. In the discussion on global variables in threads, we used a procedure create_global to allocate storage for a pointer to the variable, rather than the variable itself. Is this essential, or could the procedures work with the values themselves just as well? 21. Consider a system in which threads are implemented entirely in user space, with the run-time system getting a clock interrupt once a second. Suppose that a clock interrupt occurs while some thread is executing in the run-time system. What problem might occur? Can you suggest a way to solve it? 22. Suppose that an operating system does not have anything like the select system call to see in advance if it is safe to read from a file, pipe, or device, but it does allow alarm clocks to be set that interrupt blocked system calls. Is it possible to implement a threads package in user space under these conditions? Discuss. 23. Does the busy waiting solution using the turn variable (Fig. 2-23) work when the two processes are running on a shared-memory multiprocessor, that is, two CPUs sharing a common memory? 24. Does Peterson's solution to the mutual-exclusion problem shown in Fig. 2-24 work when process scheduling is preemptive? How about when it is nonpreemptive? 25. Can the priority inversion problem discussed in Sec. 2.3.4 happen with user-level threads? Why or why not? 26. In Sec. 2.3.4, a situation with a high-priority process, H , and a low-priority process, L, was described, which led to H looping forever. Does the same problem occur if roundrobin scheduling is used instead of priority scheduling? Discuss. 27. In a system ·with threads, is there one stack per thread or one stack per process when user-level threads are used? What about when kernel-level threads are used? Explain. 176 PROCESSES AND THREADS CHAP. 2 28. When a computer is being developed, it is usually first simulated by a program that runs one instruction at a time. Even multiprocessors are simulated strictly sequentially like this. Is it possible for a race condition to occur when there are no simultaneous events like this? 29. The producer-consumer problem can be extended to a system with multiple producers and consumers that write (or read) to (from) one shared buffer. Assume that each producer and consumer runs in its own thread. Will the solution presented in Fig. 2-28, using semaphores, work for this system? 30. Consider the following solution to the mutual-exclusion problem involving two processes PO and P1. Assume that the variable tum is initialized to 0. Process PO's code is presented below. r Other code •t while (turn != 0) { } r Do nothing and wait. */ Critical Section I* ... *I turn= 0; r Other code •t For process P 1, replace 0 by 1 in above code. Determine if the solution meets all the required conditions for a correct mutual-exclusion solution. 31. How could an operating system that can disable interrupts implement semaphores? 32. Show how counting semaphores (i.e., semaphores that can hold an arbitrary value) can be implemented using only binary semaphores and ordinary machine instructions. 33. If a system has only two processes, does it make sense to use a barrier to synchronize them? Why or why not? 34. Can two threads in the same process synchronize using a kernel semaphore if the threads are implemented by the kernel? What if they are implemented in user space? Assume that no threads in any other processes have access to the semaphore. Discuss your answers. 35. Synchronization within monitors uses condition variables and two special operations, wait and signal. A more general form of synchronization would be to have a single primitive, waituntil, that had an arbitrary Boolean predicate as parameter. Thus, one could say, for example, waituntil x < 0 or y + z < n The s ignal primitive would no longer be needed. This scheme is clearly more general than that of Hoare or Brinch Hansen, but it is not used. Why not? (Hint: Think about the implementation.) 36. A fast-food .restaurant has four kinds of employees: (1) order takers, who take customers' orders; (2) cooks, who prepare the food; (3) packaging specialists, who stuff the food into bags; and (4) cashiers, who give the bags to customers and take their money. Each employee can be regarded as a communicating sequential process. What form of interprocess communication do they use? Relate this model to processes in UNIX. PROBLEMS CHAP. 2 177 37 . Suppose that we have a message-passing system using mailboxes. When sending to a full mailbox or trying to receive from an empty one, a process does not block. Instead, it gets an error code back. The process responds to the error code by just trying again, over and over, until it succeeds. Does this scheme lead to race conditions? 38. The CDC 6600 computers could handle up to 10 l/0 processes simultaneously using an interesting form of round-robin scheduling called processor sharing. A process switch occurred after each instruction, so instruction 1 came from process 1, instruc- tion 2 came from process 2, etc. The process switching was done by special hardware, and the overhead was zero. If a process needed T sec to complete in the absence of competition, how much time would it need if processor sharing was used with n processes? 39. Consider the following piece of C code: void mai'n( ) { fork( ); fork(); exit( ); } How many child processes are created upon execution of this program? 40. Round-robin schedulers normally maintain a list of all runnable processes, with each process occurring exactly once in the list. What would happen if a process occurred twice in the list? Can you think of any reason for allowing this? 41. Can a measure of whether a process is likely to be CPU bound or I/0 bound be deter- mined by analyzing source code? How can this be determined at run time? 42. Explain how time quantum value and context switching time affect each other, in a round-robin scheduling algorithm. 43. Measurements of a certain system have shown that the average process runs for a time T before blocking on 1/0. A process switch requires a time S, which is effectively wasted (overhead). For round-robin scheduling with quantum Q, give a formula for the CPU efficiency for each of the following: (a) Q =co (b) Q> T (c)S Purchase answer to see full attachment

Tutor Answer

cobraboy402
School: Cornell University

Hey there buddy, here's what I've got for you. I couldn't answer the first and last questions from Chapter 2. Hope that this helps you out.

Ch. 1
1. What are the two main functions of an operating system?
A. Allows the hardware and software to interact.
B. Manages the storage of data
9. There are several design goals in building an operating system, for example,

resource utilization, timeliness, robustness, and so on. Give an example of two design
goals that may contradict one another.
Main memory is normally divided up among several running programs, so each one can be
resident at the same time. Assuming there is enough memory to hold multiple programs, it is more
efficient to hold several programs in memory at once rather than to give one of them all of it, especially
if it only needs a fraction of the total. This in turn brings about the contradiction by raiding issues of
fairness and protection. Optimally, we want the operating system to run most efficiently thereby
increasing speed but we s...

flag Report DMCA
Review

Anonymous
Top quality work from this tutor! I’ll be back!

Anonymous
Heard about Studypool for a while and finally tried it. Glad I did caus this was really helpful.

Anonymous
Thank you! Reasonably priced given the quality

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4
Similar Questions
Related Tags

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors