CS 385 Test 1. 1 Apr 2004

Similar documents
Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Introduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar

Reading Assignment 4. n Chapter 4 Threads, due 2/7. 1/31/13 CSE325 - Processes 1

OS 1 st Exam Name Solution St # (Q1) (19 points) True/False. Circle the appropriate choice (there are no trick questions).

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017

CS-537: Midterm Exam (Spring 2001)

CSC 4320 Test 1 Spring 2017

Sections 01 (11:30), 02 (16:00), 03 (8:30) Ashraf Aboulnaga & Borzoo Bonakdarpour

CS510 Operating System Foundations. Jonathan Walpole

CPS 310 first midterm exam, 2/26/2014

Concurrency: Deadlock and Starvation. Chapter 6

CS153: Midterm (Winter 19)

Processes. Process Management Chapter 3. When does a process gets created? When does a process gets terminated?

CS 3013 Operating Systems WPI, A Term Assigned: Friday, August 31, 2007 Due: Monday, September 17, 2007

CSC 1600: Chapter 6. Synchronizing Threads. Semaphores " Review: Multi-Threaded Processes"

Operating Systems CMPSC 473 Midterm 2 Review April 15, Lecture 21 Instructor: Trent Jaeger

Announcements Processes: Part II. Operating Systems. Autumn CS4023

CS 318 Principles of Operating Systems

Chapter 6: Process Synchronization

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

CROWDMARK. Examination Midterm. Spring 2017 CS 350. Closed Book. Page 1 of 30. University of Waterloo CS350 Midterm Examination.

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

CS 5460/6460 Operating Systems

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

Universidad Carlos III de Madrid Computer Science and Engineering Department Operating Systems Course

Chapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6.

Q1. State True/false with jusification if the answer is false:

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes

CS2506 Quick Revision

CS 370 Operating Systems

Operating Systems Comprehensive Exam. Spring Student ID # 3/20/2013

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes

Midterm Exam CPS 210: Operating Systems Spring 2013

Computer Systems II. First Two Major Computer System Evolution Steps

Process Synchronization. CISC3595, Spring 2015 Dr. Zhang

Processes. Process Concept

SOFTWARE ARCHITECTURE 3. SHELL

There are 8 total numbered pages, 6 Questions. You have 60 minutes. Budget your time carefully!

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Outline. OS Interface to Devices. System Input/Output. CSCI 4061 Introduction to Operating Systems. System I/O and Files. Instructor: Abhishek Chandra

COMP 3100 Operating Systems

Operating Systems Comprehensive Exam. Fall Student ID # 10/31/2013

CS370 Operating Systems

* What are the different states for a task in an OS?

Contents. IPC (Inter-Process Communication) Representation of open files in kernel I/O redirection Anonymous Pipe Named Pipe (FIFO)

CSC209 Review. Yeah! We made it!

CS 3214 Midterm. Here is the distribution of midterm scores for both sections (combined). Midterm Scores 20. # Problem Points Score

CPS 310 midterm exam #2, 4/10/2017

Systems Programming/ C and UNIX

Operating Systems: William Stallings. Starvation. Patricia Roy Manatee Community College, Venice, FL 2008, Prentice Hall

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes

Logical disks. Bach 2.2.1

Midterm Exam. October 20th, Thursday NSC

Pipes and FIFOs. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Process Synchronization(2)

Lecture Topics. Announcements. Today: Concurrency (Stallings, chapter , 5.7) Next: Exam #1. Self-Study Exercise #5. Project #3 (due 9/28)

CSE 153 Design of Operating Systems

Final exam. Scores. Fall term 2012 KAIST EE209 Programming Structures for EE. Thursday Dec 20, Student's name: Student ID:

CS 345 Operating Systems. Tutorial 2: Treasure Room Simulation Threads, Shared Memory, Synchronization

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CS3502 OPERATING SYSTEMS

CSCI 4061: Virtual Memory

(MCQZ-CS604 Operating Systems)

CPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.

VEOS high level design. Revision 2.1 NEC

Last Class: Synchronization Problems. Need to hold multiple resources to perform task. CS377: Operating Systems. Real-world Examples

Process Synchronization

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

2.c Concurrency Mutual exclusion & synchronization mutexes. Unbounded buffer, 1 producer, N consumers

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

COMP 2355 Introduction to Systems Programming

Computer Systems Assignment 2: Fork and Threads Package

Shared Memory. By Oren Kalinsky

UNIX Input/Output Buffering

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Computer Systems Engineering: Spring Quiz I Solutions

CSE 120 Principles of Computer Operating Systems Fall Quarter, 2002 Halloween Midterm Exam. Instructor: Geoffrey M. Voelker

Process a program in execution; process execution must progress in sequential fashion. Operating Systems

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

CS 326: Operating Systems. Process Execution. Lecture 5

EECS 482 Introduction to Operating Systems

Windows architecture. user. mode. Env. subsystems. Executive. Device drivers Kernel. kernel. mode HAL. Hardware. Process B. Process C.

Dr. D. M. Akbar Hussain DE5 Department of Electronic Systems

Getting to know you. Anatomy of a Process. Processes. Of Programs and Processes

Spring CS 170 Exercise Set 1 (Updated with Part III)

Last Class: Deadlocks. Today

What Is A Process? Process States. Process Concept. Process Control Block (PCB) Process State Transition Diagram 9/6/2013. Process Fundamentals

Concurrency: Deadlock and Starvation

csci3411: Operating Systems

Processes. CS439: Principles of Computer Systems January 30, 2019

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CS604 Final term Paper Fall (2012)

Lecture 9: Midterm Review

CS 322 Operating Systems Practice Midterm Questions

CHAPTER 6: PROCESS SYNCHRONIZATION

CSC369 Lecture 2. Larry Zhang

Transcription:

CS 385 Test 1 1 Apr 2004 Instructor: Jon A. Solworth Name/SSN: Short questions: answer on exam sheet. 1. Unix Programming (12pts.) Using only system calls such as read, write, fork, exec, dup, pipe, write a program fragment which will create a pipe and a child process. The child should write to the pipe hi there and the parent will read the string. The child process should terminate and the parent should check its status. int fd ; p i d t c h i l d ; char buf [ 1 0 2 4 ] ; i f ( pipe ( fd ) < 0) p r i n t f ( Error c r e a t i n g pipe ) ; i f ( ( c h i l d = f o r k ( ) ) < 0 ) p r i n t f ( Error c r e a t i n g c h i l d ) ; i f ( c h i l d == 0) char s t r = Hi There!! ; c l o s e ( fd [ 0 ] ) ; w r i t e ( fd [ 1 ], str, s t r l e n ( s t r ) + 1 ) ; else c l o s e ( fd [ 1 ] ) ; read ( fd [ 0 ], buf, 1 0 2 4 ) ; wait (NULL) ; 1

2. Unix Programming (12pts.) Using only system calls such as read, write, fork, exec, dup, pipe, write a program fragment which creates a new process which will execute the program ls >out. (The >out means that the file out replaces standard output before the ls is executed.). Note that the executable ( ls ) and the output file ( out ) are not parameters, they are fixed for the program fragment. char prog = l s ; char f i l e n a m e = out ; p i d t c h i l d ; i f ( ( c h i l d = f o r k ( ) ) < 0 ) p r i n t f ( Error c r e a t i n g c h i l d ) ; i f ( c h i l d == 0) int fd = open ( filename, O RDWR O CREAT, S IRWXU ) ; i f ( fd < 0) c l o s e ( 1 ) ; dup ( fd ) ; i f ( e x e c l p ( prog, NULL) < 0) wait (NULL) ; 3. Unix Programming (12pts.) Using only system calls write a program fragment that maps an existing shared memory object shmlist, and initializes the linked list in shared memory. Each node in the list contains two fields value (int) and next. The constant listcount contains the number of nodes. Assume that this is the only process updating the shared memory object. struct node int value ; int next ; nodeptr ; int shmid = shm open ( / shmlist, O RDWR) ; nodeptr = ( struct node ) mmap(null, PROT READ PROT WRITE, MAP SHARED, shmid, 2

l i s t C o u n t sizeof ( struct node ), 0 ) ; for ( int i =0; i < l i s t C o u n t ; i ++) / i n i t i a l i z e / nodeptr [ i ]. next = i +1; nodeptr [ listcount 1]. next = 1; / 1 f o r NULL / 4. Semaphores (12 pts.) Consider a game in which each player p can either increase the p s position by 1 (increment(int player)) or decrease the p s position by 1 (decrement(int player)), to a minimum of 0. (Presumably the player either increases her position or decreases another players position.) The first player to reach 10 wins and only that player should set the variable winner to the player number. Implement increment(int player) and decrement(int player) using semaphores, so that each player s position can concurrently be updated and exactly one process writes winner. // shared v a r i a b l e s int winner = 1; // no winner y e t int p o s i t i o n [ PlayerCount ] ; // a l l z e r o s semaphore mutex [ PlayerCount ] = 1 ; // g e n e r a l purpose semaphore winnermutex = 1 ; void increment ( int p l a y e r ) wait ( mutex [ p l a y e r ] ) ; p o s i t i o n [ p l a y e r ]++; i f (10== p o s i t i o n [ p l a y e r ] ) wait ( winnermutex ) ; i f ( 1==winner ) winner=p l a y e r ; s i g n a l ( winnermutex ) ; s i g n a l ( mutex [ p l a y e r ] ) ; void decrement ( int p l a y e r ) wait ( mutex [ p l a y e r ] ) ; i f ( p o s i t i o n [ p l a y e r ] >0) 3

p o s i t i o n [ p l a y e r ] ; s i g n a l ( mutex [ p l a y e r ] ) ; 5. Semaphores (10pts.) Consider a concurrent system with two queues, q1 and q2. Concurrent inserts should be allowed on q1 and q2, but dequeue should remove an element from q1 (if q1 is not empty) otherwise from q2 (if q2 is not empty). Implement a semaphore based program the routines insert and remove. i n s e r t ( int queue, Elmt elmt ) i f (1==queue ) wait ( sem1 ) ; q1. append ( elmt ) ; s i g n a l ( sem1 ) ; else wait ( sem2 ) ; q2. append ( elmt ) ; Elmt remove ( ) Elmt elmt ; wait ( sem1 ) ; i f (! q1. empty ( ) ) elmt = q1. dequeue ( ) ; return elmt ; s i g n a l ( sem1 ) ; // q1 empty, t r y q2 wait ( sem2 ) ; i f (! q2. empty ( ) ) elmt = q2. dequeue ( ) ; return elmt ; 4

return NULL; 6. Deadlock (12pts.) Describe whether deadlock is avoided or not. If avoided, describe what condition of Dijkstra s is violated to prevent deadlock. If not avoided, give an example of deadlock. (a) Resources are A, B, C. Request any subset of the resources in the order A, C, B. ans. Avoids deadlock by preventing circular wait. (b) Resources are numbered 1,2,3,... Request odd resources before even resources. ans. Can deadlock if one process requests 1,3 and a second process requests 3,1. (c) If a process requests a resource, and the resource is unavailable, one of the resources the process currently has is returned to the system, and the process must repeat the request again. ans. Avoids deadlock since it (eventially) denies hold and wait. (d) Every 10 minutes all the processes in the system are killed. ans. Avoids deadlock through preemption. Note that deadlock is an indefinite wait. 7. Architectural Support for OS (12pts.) Each of the following are special purpose processors registers. For each, describe its purpose and when it changes. (a) Privilege Bit ans. Ensures that processes cannot violate the process model by requiring those instructions necessary to manipulate processes to be executed only in privilege mode. (Privilege mode is off while executing processes and on when executing in the kernel.) It is set on processor initialization, on traps, and on interrupts. It is cleared by rtt and rti. (b) TrapVectorPtr ans. Used by trap instructions to ensure that the kernel is only entered at well defined entry points. Set at kernel load time. (c) base ans. ensures process does not access memory before the process is located. Changed when entering the kernel and when returning to the process. (d) limits ans. ensures process does not access memory after the process is located. Changed when entering the kernel and when returning to the process. (e) IntrVectorPtr ans. points to a vector which specifies entry points (addresses) in the kernel to begin execution for each interrupt type. Changes only on system initialization 5

(f) InterruptMask ans. allows interrupts to be turned off when updating a data structure that an interrupt might also update. Interrupt masking is set by privilege instructions. 8. Interference (8pts.) What are the possible outcomes of interleavings, assuming all variables are shared and initially 0 in the below questions. Show the value of the variables at completion and an instruction interleaving which achieves each set of values. Each of two processes execute the sequence i +=1; j=i ; Which is compiled into 5 machine language instruction (load-increment-store,loadstore)? ans. process a:(a1,a2,a3,a4,a5) and process b:(b1,b2,b3,b4,b5) i = j = 2 a1,a2,a3,a4,a5,b1,b2,b3,b4,b5 i = j = 1 a1,b1,b2,b3,b4,b5,a2,a3,a4,a5 i = 2, j = 1 a1,a2,a3,a4,b1,b2,b3,b4,b5,a5 One process executes x = 1; y = x and the other process z = y; x = y? ans. process a:(a1,a2,a3) store, load, store and process b:(b1,b2,b3,b4) load, store, load, store x = 0, y = 0, z = 0 b1,b2,a1,b3,b4,a2,a3 x = 1, y = 1, z = 1 a1,a2,a3,b1,b2,b3,b4 x = 1, y = 1, z = 0 b1,b2,a1,a2,a3,b3,b4 x = 0, y = 1, z = 0 a1,b1,b2,b3,a2,a3,b4 9. Implementing Processes (10pts.) In what ways might a process try to interfere with another process and what is the technique by which it is prevented? reading or writing another process s or the kernel s memory: Base and limits registers. infinite loop timer interrupt take control over some resource resource allocation is controlled by the OS, and those resources that do not have to be allocated exclusively to a process are managed by the OS. 6