4.1 Provide two programming examples in which multithreading does notprovide better performance than a single-threaded solutionAnswer: (1) Any kind of sequential program is not a good candidateto be threaded. An example of this is a program that calculates an individualtax return. (2) Another example is a "shell" program such asthe C-shell or Korn shell. Such a program must closely monitor its ownworking space such as open files, environment variables, and currentworking directory.4.2 Describe the actions taken by a thread library to context switch betweenuser-level threads.Answer: Context switching between user threads is quite similar toswitching between kernel threads, although it is dependent on thethreads library and how it maps user threads to kernel threads. Ingeneral, context switching between user threads involves taking a userthread of its LWP and replacing it with another thread. This act typicallyinvolves saving and restoring the state of the registers.4.3 Under what circumstances does a multithreaded solution using multiplekernel threads provide better performance than a single-threadedsolution on a single-processor system?2324 Chapter 4 ThreadsAnswer: When a kernel thread suffers a page fault, another kernelthread 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 ofperforming useful work when a page fault takes place. Therefore, inscenarios where a program might suffer from frequent page faults or
Exercises3.1 Describe the differences among short-term, medium-term, and longtermscheduling.Answer:? Short-term (CPU scheduler)?-selects from jobs in memory thosejobs that are ready to execute and allocates the CPU to them.? Medium-term?-used especially with time-sharing systems as anintermediate scheduling level. A swapping scheme is implementedto remove partially run programs from memory and reinstate themlater to continue where they left off.? Long-term (job scheduler)?-determines which jobs are brought intomemory for processing.The primary difference is in the frequency of their execution. The shorttermmust select a new process quite often. Long-term is usedmuch lessoften since it handles placing jobs in the system and may wait a whilefor a job to finish before it admits another one.1516 Chapter 3 Processes3.2 Describe the actions taken by a kernel to context-switch between processes.Answer: In general, the operating system must save the state of thecurrently running process and re.does not require these semantics.3.4 Using the program shown in Figure 3.24, explain what will be output atLine A.Answer: Please refer to the supportingWeb site for source code solution.3.5 What are the benefits and detriments of each of the following? Considerboth the systems and the programmers’' levels.a. Symmetric and asymmetric communicationb. Automatic and explicit bufferingc. Send by copy and send by referenced. Fixed-sized and variable-sized messagesAnswer:a. Symmetric and asymmetric communication - A benefit of symmetriccommunication is that it allows a rendezvous between thesender and receiver. A disadvantage of a blocking send is that arendezvous may not be required and the message could be deliveredasynchronously; received at a point of no interest to theExercises 17sender. As a result, message-passing systems often provide bothforms of synchronization.b. Automatic and explicit buffering -Automatic buffering providesa queuewith indefinite length; thus ensuring the senderwirite a C program using the fork() system call that that generates theFibonacci sequence in the child process. The number of the sequencewill be provided in the command line. For example, if 5 is provided, thefirst five numbers in the Fibonacci sequence will be output by the childprocess. Because the parent and child processes have their own copiesof the data, it will be necessary for the child to output the sequence.Have the parent invoke the wait() call to wait for the child process tocomplete before exiting the program. Perform necessary error checkingto ensure that a non-negative number is passed on the command line.Answer: Please refer to the supportingWeb site for source code solution.3.7 Repeat the preceding exercise, this time using the CreateProcess() inthe Win32 API. In this instance, you will need to specify a separate pro18Chapter 3 Processesgram to be invoked from CreateProcess(). It is this separate programthat will run as a child process outputting the Fibonacci sequence.l rather than the character level. Thus, this echo server must use anobject that extends java.io.InputStream. The read() method in thejava.io.InputStream class returns ?.1 when the client has closed itsend of the socket connection.Answer: Please refer to the supportingWeb site for source code solution.3.10 In Exercise 3.6, the child process must output the Fibonacci sequence,since the parent and child have their own copies of the data. Anotherapproach to designing this program is to establish a shared-memorysegment between the parent and child processes. This technique allowsthe child to write the contents of the Fibonacci sequence to the sharedmemorysegment and has the parent output the sequencewhen the childcompletes. Because the memory is shared, any changes the child makesto the shared memory will be reflected in the parent process as well.This program will be structured using POSIX shared memory as describedin Section 3.5.1. The program first requires creating the datastructure foe sequence. These two processeswill be synchronized using the wait() system call; the parent processwill invoke wait(), which will cause it to be suspended until the childprocess exits.Answer: Please refer to the supportingWeb site for source code solution.3.11 Most UNIX and Linux systems provide the ipcs command. This commandlists the status of various POSIX interprocess communicationmechanisms,including shared-memory segments. Much of the informationfor the command comes from the data structure struct shmid ds,which is available in the /usr/include/sys/shm.h file. Some of thefields of this structure include:?int shm segsz?ize of the shared-memory segment?short shm nattch?umber of attaches to the shared-memorysegment20 Chapter 3 Processes?struct ipc perm shm perm?ermission structure of theshared-memory segmentThe struct ipc perm data structure (which is available in the file/usr/include/sys/ipc.h) contains the fields:?unsigned short uid?dentifier of the user of theshared-memory segmenon.
2.1 The services and functions provided by an operating system can bedivided into two main categories. Briefly describe the two categoriesand discuss how they differ.Answer: One class of services provided by an operating system is toenforce protection between different processes running concurrently inthe system. Processes are allowed to access only thosememory locationsthat are associated with their address spaces. Also, processes are notallowed to corrupt files associated with other users. A process is also notallowed to access devices directly without operating system intervention.The second class of services provided by an operating system is toprovide new functionality that is not supported directly by the underlyinghardware. Virtual memory and file systems are two such examplesof new services provided by an operating system.2.2 List five services provided by an operating system that are designed tomake it more convenient for users to use the computer system. In whatcases it would be impossible for user-level programs to provide theseservices? Explain.
Exercises1.1 In a multiprogramming and time-sharing environment, several usersshare the system simultaneously. This situation can result in varioussecurity problems.a. What are two such problems?b. Can we ensure the same degree of security in a time-shared machineas in a dedicated machine? Explain your answer.Answer:a. Stealing or copying one’`s programs or data; using system resources(CPU, memory, disk space, peripherals) without properaccounting.b. Probably not, since any protection scheme devised by humanscan inevitably be broken by a human, and the more complexthe scheme, the more difficult it is to feel confident of its correctimplementation.12 Chapter 1 Introduction1.2 The issue of resource utilization shows up in different forms in differenttypes of operating systems. List what resources must be managedcarefully in the following settings:a. Mainframe or minicomputer systemsb. Workstations connected to serversc. Handheld computers
9.3A page-replacement algorithm should minimize the number of page faults. We can achieve this minimization by distributing heavily used pages evenly over all memory, rather than having them compete for a small number of page frames. We can associate with each page frame a counter of the number of pages associated with that frame. Then, to replace a page, we can search for the page frame with the smallest counter.?a. Define a page-replacement algorithm using this basic idea. Specifically address these problems:1. What is the initial value of the counter is2. When counters are increased3. When counters are decreased4. How is the page to be replaced selected-FIFO알고리즘을 개선하여 카운터의 초기값을 모두 0으로 줍니다. 그 후 참조가 일어나면 카운터를 증가시키고 5회의 명령어가 지나갈 정도의 일정시간이 지나면 모두의 카운터를 하나 감소시킵니다. 교체할 때는 카운터의 값이 가장 작은 것을 교체합니다. 이 알고리즘의 단점은 시작한지 얼마 안된 프로세스가 부른 페이지는 사용한지 얼마 안됐기 때문에 카운트 값이 작아 자주 교체되어버린다.?b. How many page faults occur for your algorithm for the following reference string, with four page frames?1,2,3,4,5,3,4, 9 9?? 9 9 9 9 9?? 9f f f f f?? h h f f f?? f h h f h?? h h f f f?? f? =>? 14?c. What is the minimum number of page faults for an optimal page-replacement strategy for the reference string in part b with four page frames??-11번 일어납니다.1 1 1 1 1?? 6 6 8 8 4?? 29.6Consider a demand-paging system with a paging disk that has an averageaccess and transfer time of 20milliseconds. Addresses are translated through a page table inmainmemory, with an access time of 1microsecond per memory access. Thus, eachmemory reference through the page table takes two accesses. To improve this time, we have added an associative memory that reduces access time to one memory reference, if the page-table entry is in the associative memory.Assume that 80 percent of the accesses are in the associative memory and that, of the remaining, 10 percent (or 2 percent of the total) cause page faults.What is the effective memory access time?효과적인 액세스 시간= (0.8) × (1 sec)+ (0.1) × (2 sec) + (0.1) × (5002 sec)= 501.2 sec= 0.5 m seven frames?Remember that all frames are initially empty, so your first unique pages will cost one fault each.●LRU replacement●FIFO replacement●Optimal replacementNumber of framesLRUFIFOOptimal1*************3*************81*************.11Discuss situationsunderwhich the least frequentlyused page-replacementalgorithm generates fewer page faults than the least recently used pagereplacementalgorithm. Also discuss under what circumstance does theopposite holds.메모리 액세스의 순서를 고려 메모리에 4 개의 페이지를 저장할 수 있는 시스템이다.순서 : 1 1 2 3 4 5 1. 때는 5 페이지가 자주 페이지 - 대체를 사용하여 최소 액세스알고리즘은 대체할 것이 아닌 다른 1, 페이지 그러므로 않을 페이지 1 페이지 오류를 가져다가 다시 액세스할 수 있습니다. 순서는 "1 2 3 4 5 2,"적어도 최근에 사용한 알고리즘을 수행 더 해야한다.9.16 Consider the two-dimensional array A:int A [] [] = new int[100] [100];where A[0] [0] is at location 200 in a paged memory system with pages of size 200. A small process that manipulates the matriz resides in page0(locations 0 to 199). Thus, every instruction fetch will be from page0.For three page frames, how many t I = 0; i< 100; I++)A[i][j] = 0;b. for (int i =0; I < 100; I++)for (int j =0; j < 100; j++)A[i][j] = 0;page에 저장될 때 행 우선(row-major) 방식으로 저장된다고 가정하면, 배열의 전체 사 이즈는 10,000개이다. a와 같이 열에 대한 for 문이 바깥 루프에 있다면, 배열의 원소에 대 한 참조가 page에 저장된 행의 순서가 아니라 열의 순서대로 이루어지므로 배열의 한 원소 를 참조할 때마다 page fault가 일어나 총 10,000번의 page fault가 발생할 것이다. 하지만 b와 같이 행에 대한 for 문이 바깥 루프로 존재하면, page에 저장된 형태와 같이 행의 순으 로 참조가 일어나 일단 하나의 page를 불러오면 200개의 배열 원소를 참조할 수 있다. 따 라서 b의 경우는 50번의 page fault가 발생할 것이다. 열 우선을 저장된다면 반대의 상황 이 될 것이다.9.21 The slab allocation algorithm uses a separate cache for each differentobject type. Assuming there is one cache per object type, explain whythis doesn’'t scalewellwithmultiple CPUs.What couldbedone toaddressthis scalability issue?이것은 긴 슬라브 할당자에 문제가 있기 때문이다.다중 프로세서 시스템에서 캐시 액세스하고 솔라리스 의하여 이 문제를 해결할수 있다.9.24 Which of the following programming techniques and structures are "good" for a demand-paged environment? Which are "not good"? Explain your answers.a. statck b. 해쉬 기호표( hashed symbol table )c원하면 프로세스가 기억 장치에 적재된다. 모든 프로세스를 교체하는 대신에 page는 단지 필요한 page만 메모리로 가져온다. 그래서 사용되지 않는 메모리 page를 읽는 것을 피함과 동시에 교체 시간을 감소 시키고 필요한 실제 메모리의 총량을 감소시킨다.9.28 A certain computer provides its users with a virtual-memory space of232 bytes. The computer has 218 bytes of physical memory. The virtualmemory is implemented by paging, and the page size is 4096 bytes.A user process generates the virtual address 11123456. Explain howthe system establishes the corresponding physical location. Distinguishbetween software and hardware operations.이진 형태로 가상 주소는 0001 0001 0001 0010 0011 0100 0101 0110페이지 크기가 212이기 때문에, 페이지 테이블 크기는 220입니다. 따라서 loworder12 비트는 "0100는 0101 0110"페이지에 변위으로 사용됩니다나머지 20 비트가 "0001 0001 0001 0010 0011"로 사용하는 동안페이지 테이블의 변위 합니다.9.31Consider the parameter Δ used to define the working-set window in the working-set model. What is the effect of setting Δ to a small value on the page fault frequency and the number of active (non-suspended) processes currently executing in the system? What is the다.