***************Work Sheet 0************************** Do the following Problems. 1.What are the major achievements (listed below are some possibilities) in operating systems work in the late 20th Century. (explain why do you think so) 1. Multi tasking 2. Time Sharing 3. File Sharing 4. Concurrency 5. Security 6. Networking. ###:Networking. Networking is the major achievement not only for its new technology, but also for allowing people to communicate easily and to share resources. 2.What are the major stumbling blocks (listed below are some of the possibilities) in the operating systems work in the late 20th Century. (explain why do you think so) 1. Speed 2. Portability 3. Bandwidth 4. Stability 5. UN-intuitive 6. Security 7. Too hard for application developer. ###:Maybe bandwidth because of the networking improtance. 3.What will be the operating system for the 21st century (listed below are some of the possibilities). (explain why do you think so) 1. Web-TV 2. OS based on Java 3. Windows NT 4. Unix based 5. Mac OS 6. DOS ###:OS based on Java. Java is popular because it provides the novel idea for independent from hardware. ***************Work Sheet 1************************** Do problems 2.4, 2.5 and 2.10 ###2.4 DMA is used for high-speed I/O devices. After setting up buffers, pointers and counters for the I/O device, the device controller transfers an entire block of data directly to or from its own buffer storage to memory, with no intervention by the CPU. ###2.5 the choice is a, c, d, and e. ###2.10 1. To prevent a user from performing illegal I/O, we define all I/O instructions to be privileged instructions. For I/O protection to be complete, we must be sure that a user progrma can never gain control of the computer in monitor mode. 2. CPU hardware compares every address generated in user mode with the register. Any attempt by a program executing in user mode to access monitor memory or other users' memory or other users' memory results in a trap to the monitor, which treats the attempt as a fatal error. 3.Before turning over control to the user, the operating system ensures that the timer is set to interrupt. Thus, we can use the timer to prevent a user program from running too long. Do Problems 3.2 to 3.6 of S&G ###3.2 1.Keep track of which parts of memory are currently being used and by whom. 2.Decide which processes are to be loaded into memory when memory space becomes available. 3.Allocate and deallocate memory space as needed. ###3.6 Five services: 1.Program execution. 2.I/O operations 3.File-system manipulation 4.Communications 5.Error detection Consider a memory system with the following parameters: T_cache = 100 nanosec C_cache = 0.01 cents/bit T_memory = 1200 nanosec C_memory = 0.001 cents/bit Hit Ratio = 0.95 a) What is the cost of 1 MB of main memory? ### 1*1024*1024*8*0.001cents=$84. b) What is the cost of 1 MB of main memory using cache technology? ### 1*1024*1024*8*0.01cents=$840. c) Design a main memory/cache system with 1 MB of main memory whose effective access time is no more than 10% greater than cache memory access time. What is its cost? ### The effective access time ( from the equation 1.1 given in page 39) with T1 = 100 ns and T2 = 1200 ns. we get Ts = T1 +(1-H) (T1+T2) = 100 + 0.05 * 1300 ns = 165 ns Since we need an access efficiency of 110 ns, the hit ratio has to be improved: 110 = 100 + (1-H) * 1300 10/1300 = 1-H H = 1290/1300 = 0.99 The ratio of the size ( s1/s2) has to be 0.1 ( for strong locality) by looking at performance curve. cache has .1 M and main memory is .9 M cost is 83.89+75.49 = $159.38 A main memory system consists of a number of memory modules attached to the system bus. When a write request is made, the bus is occupied for 100 nanosec by the data, address and control signals. During the same 100nanosec and for 500nanosec thereafter memory module executes one cycle accepting, and storing the data. The operation of the memory modules may overlap, but only one request can be on the bus any time. Assume that there are eight such modules connected to the bus. What is the maximum possible rate (in bytes per second) at which data can be stored. ### In a cycle, maximum possible data = 8* (100+500)/100=48bits=6bytes The maximum possible rate= 6/0.0006=10000bytes/second ***************Work Sheet 2************************** 1.What is a process? ###A process is a program in execution. 2.What is a PCB? ###PCB is a process control block, including these: Process state, Program counter, CPU registers, CPU scheduling information, Memory-managemnet information , Accounting information and I/O status information. 3.List some of the queues in a typical system? ### ready queue, wait queue, device queue etc. 4.How many device queues are there on a system? ###Every device has its own device queue. Thus, the amount of device queues is equal to that of devices. 5.Do problems 4.7, 4.8 and 4.9 of S&G 4.7 ### A kenel thread has only a small data structure and a stack. Switching between kernel threads does not require changing memory access information, and therefore is relatively fast. A user-level thread needs only a stack and a program counter: no kernel resources are required. The kernel is not involved in scheduling these thousands of these user-level threads, but all the kernel will ever see is the LWPs in the process that support these user-level threads. 4.8 ### boolean full[n]; /* all initialized to false */ Producer: repeat ... produce an item in nextp; while full[in] do no-op; buffer[in]:=nextp; full[in] = true; in:=in+1 mod n; until false; Consumer: repeat while (!full[out]) do no-op; nextc:=buffer[out]; full[out]=false; out:=out+1 mod n; overflow =0; ... consume the item in nextc ... until false; 4.9 ### a. Any order of these messages: receive(A, msg) receive(B, msg) b. receive(A,msg) or receive(B,msg) c. use bounded buffer scheme. ***************Work Sheet 3************************** 1.What is a CPU burst? What is I/O burst? ### CPU burst: A time interval when a process uses CPU only. I/O burst: A time interval when a process uses I/O devices only. 2.A CPU bound program would typically have what kind of I/O burst? ### Short 3.List performance criteria one would select to optimize ones system ### CPU utilization, Throughtput, Turnround time, Waiting time and Response time. 4.What is a throughput? ### Number of jobs done per period. 5.What is a convoy effect? ### Occurs when we have one CPU-bound job and many I/O bound jobs. The I/O bound jobs are lined up in a convoy, waiting for the CPU-bound job to finish up. 6.What is an exponential averaging? ### A way of using previous history of job to predict length of next CPU burst. An exponential average is defined as follows: S(n+1)=a*T(n)+(1-a)Sn. 7.Do Problems 5.1, 5.3, 5.4, 5.6, 5.7 and 5.10 of S&G 5.1 ### n! 5.3 ### a.Grantt Charts 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 FCFS 1 1 1 1 1 1 1 1 1 1 2 3 3 4 5 5 5 5 5 SJF 2 4 3 3 5 5 5 5 5 1 1 1 1 1 1 1 1 1 1 NonP 2 5 5 5 5 5 1 1 1 1 1 1 1 1 1 1 3 3 4 RR 1 2 3 4 5 1 3 5 1 5 1 5 1 5 1 1 1 1 1 b.Turnround Time FCFS p1=10 p2=11 p3=13 p4=14 p5=19 SJF p1=19 p2=1 p3=4 p4=2 p5=9 NonP p1=16 p2=1 p3=18 p4=19 p5=6 RR p1=19 p2=2 p3=7 p4=4 p5=14 c.Waiting Time FCFS p1=0 p2=10 p3=11 p4=13 p5=14 SJF p1=9 p2=0 p3=2 p4=1 p5=4 NonP p1=6 p2=0 p3=16 p4=18 p5=1 RR p1=9 p2=1 p3=5 p4=3 p5=9 d. SJF 5.4 ### a.FCFS Turnround Time: p1=8 p2=11.6 p3=12 average T=10.5 b.SJF Turnround Time: p1=8 p2=12.6 p3=8 average T=9.53 c. Turnround Time: p1=14 p2=5.6 p3=1 average T=6.9 5.6 ### Processes which need more frequent servicing can be in a queue with a small time quantum. Porcesses with no need for frequent servicing can be in a queue with a larger time quantum, requiring fewer context switches to complete the processing. 5.7 ### a. FCFS b. LIFO 5.10 ### FCFS short processes can't get any favor. RR short processes can get some favor because they can be completed in a short time. MFQS short processes can get lots of favor. Even the short processes can be completed in a short limited time. ***************Work Sheet 4************************** 1.What is a critical section? ### A section of code that only one process at a time is executing. 2.What is a critical section problem? ### To design an algorithm that allows at most one process into the critical section at atime without deadlock. 3.Name three requirements for the solution to critical section problem. ### Mutual Exclusion, Progress and Bounded Waiting. 4.What does execute "atomically" mean? ### Executed as a group, with no context switches possible until all of the statements in the group are completed. 5.Suppose we want to execute the statements s1,s2 and s3 such that s3 can proceed only after completion of s1 and s2 and s1 and s2 can go at the same time. How do you accomplish this using semaphore? ### binary semaphore bs1=0,bs2=0; cobegin s1; signal(bs1); s2; signal(bs2); wait(bs1);wait(bs2); s3; coend; 6.Do problems 6.1, 6.3, 6.6 and 6.7 6.1 ### Busy waiting occurs when the CPU loops continuously, doing nothing useful, but waiting for some events to occur. A process can also be blocked-waiting in a queue. If the implementation of the semaphores can avoid waiting. But some busy waiting maybe involve in. 6.3 ### Pi enters its critical section only if either flag[j]=F or turn=i. If both processes can be excuting in their critical sections at the same time, the flag[0]=flag[1]=T. Since Turn can be 0 or 1, but cannot both. Thus, only one process can enter the critical section successfully(mutual excusion). Pi can be prevented from entering the critical section only if it is stuck in the WHILE loop with the condition flag[j]=T and turn=j. If Pj is not ready to enter the critical section, the flag[j]F and Pi can enter the critical section. If Pj has set flag[j]=T and is also executing in its WHILE statement, then either turn=i or turn =j. If turn =i, the Pi will enter the critical section. If turn=j, then Pj will enter the critical section. However, once Pj exists its critical section, it will reset flag[j] to F, allowing Pi to enter its critical section. If Pj resets flag[j] to T, it must also set turn=i. Thus, since Pi does not change the value of the variable turn while executing the WHILE statement, Pi will enter the critical section(progress) after at most one entry by Pj( bounded waiting). 6.6 ### wait: r1=s; r1=r1-1; s=r1; signal: r2=s; r2=r2+1; s=r2; suppose s=1, after execute wait and signal, s should be 1. But if following below sequences, r1=s;// r1=1; r2=s; // r2=1; r1=r1-1;//r1=0; s=r1;//s=0; r2=r2+1;//r2=2; s=r2;//s=2; At last, s =2. 6.7 ### Please look at the solution given in slba.java under http://www.cs.rpi.edu/~moorthy/Courses/os98/Pgms/Java/Conc/ConcProgJava/Semaphores/slba.java chair 0..n /*the number of waiting chairs*/ wakeup 0..1 /*sleep and wakeup semaphore*/ haircut 0..1 /*haircut semaphore*/ define freechair=n-chair; customer: while T do P(chair); /*get a chair num*/ if(freechair<0) /*if exceed the the chair num n*/ V(chair); /*go out */ break; endif if(chair==n) P(wakeup); V(chair); P(haricut); until F barber: while T do if(freechair==n) P(wakeup); V(haircut); P(chair); V(chiair); until F Work Sheet 5 1.What is a monitor? ### A monitor is characterized by a set of programmer-defined operators. The representation of a monitor type consists of declarations of variables whose values define the state of an instance of the type, as well as the bodies of procesures or functions that implement operations on the types. 2.What is a conditon inside a monitor? ### A condition inside a monitor is for modeling some synchroniztion mechanisms. 3.Jurassic Park consists of a dinosaur Museum and a park for safari riding. There are m passengers and n single passanger cars. Passengers wander around the mnusueum for a while, then line up to take a ride in a safari car. When a car is available, it loads the one passanger it can hold and rides around the park for a random amount of time. If the n cars are all out riding passangers around, then a passanger who wants to ride waits. Use semaphores to sy synchronize m passanger processes and n car processes. ### suppose "s" is semaphore. Initially, s=n; Every passager who want to ride the car should be as follows: { //whether the car is availble wait(s); ...ride the car... //finish the ride signal(s); } 4.Do problems 6.8, 6.14 and6.16 6.8 The Cigarette-Smokers Problem ### Each smoker should follow the procedure: paper, tabacco, and match. monitor cigarette-smockers{ private boolean P=T=M=false; //P, paper; T, tabacco; M, match condition Xp, Xt, Xm; //P, paper; T, tabacco; M, match //smoker's first step with paper public paper(){ while(T==true&&M==true) Xp.wait; P=true; ...do sth with paper... P=false; Xt.signal; Xm.signal; } //smoker's second step with tabacco public tabacco(){ while(P==true&&M==true) Xt.wait; T=true; ...do sth with tabacco... T=false; Xp.signal; Xm.signal; } //smoker's last step with match public match(){ while(T==true&&P==true) Xm.wait; M=true; ...do sth with match... M=false; Xt.signal; Xp.signal; } 6.14 Sharing the file ### Each process should do as follows: access the file, use the data, and release the file. monitor file{ private int count; //calcuate the the sum of id condition s; //acquire to access the file public acquire(int id){ while((count+id)>=n) s.wait; //n is the high level count=count+id; } //release the shared file public release(int id){ count=count-id; s.signal; } } 6.16 the alarm clock ### monitor alarm_clock{ condition s; //the alarm function public alarm(int n){ //after n time units alarm int i; for(i=0;i vector Avaiblable, the system must be unsafe. 7.13 ### a. Need=Max-Allocation, then Need: A B C D 0 0 0 0 0 7 5 0 1 0 0 2 0 0 2 0 0 6 4 2 b. Yes. P0,P2,P1,P3,P4 satisfies the safety requirement, P0 needs (0,0,0,0), after its running available will be (1,5,3,2); P2 needs (1,0,0,2), after its running available will be (2,8,8,6); P1 needs (0,7,5,0), after its running available will be (3,8,8,6); P3 needs (0,0,2,0), after its running available will be (3,14,11,8); P4 needs (0,6,4,2), after its running available will be (3,14,12,12); c. Yes. 1. (0,4,2,0) <=available (1,5,2,0); 2. (0,4,2,0) <=Max (1,7,5,0); 3. The new system system state after allocation is Allocation Max Need Available A B C D A B C D A B C D A B C D P0 0 0 1 2 0 0 1 2 0 0 0 0 1 1 0 0 P1 1 4 2 0 1 7 5 0 0 3 3 0 P2 1 3 5 4 2 3 5 6 1 0 0 2 P3 0 6 3 2 0 6 5 2 0 0 2 0 P4 0 0 1 4 0 6 5 6 0 6 4 2 And the sequence satifies the safe requirement.