Download 21 Questions on System Programming - Midterm Exam | CS 241 and more Exams Computer Science in PDF only on Docsity! University of Illinois at Urbana-Champaign Department of Computer Science Midterm Examination CS 241 System Programming Fall 2005 11-11:50 am Monday October 17 1103 Siebel Center Name: NetID: • Print your name and netid neatly in the space provided above; print your netid at the upper right corner of every page. • This is a closed book, closed notes exam. No electronic aids are allowed, either. • Ten true/false, five multiple choice, six short answer; do all parts of all six short answer. • This booklet should include this title page, plus pages 1-8. Do your work inside this booklet, using the backs of pages if needed. • Problems are of varying difficulty, hence if you don’t know the answer immediately, progress to the following problem and come back to the unsolved problem later. • Syntax is not important, but any code you write must be understood by the graders. Problem(s) Points Score 1-10 20 11-15 10 16 10 17 10 18 10 19 10 20 10 21 10 Total 90 CS 241 Midterm Exam 1 NetID: I. [True/False] Circle your answer to the left of each statement. Each correct answer in this section will be awarded 2 points. Each incorrect answer will be penalized 1 point; guessing is discouraged. 1. T F In a multithreaded program, if one thread creates a local variable, all threads will have access to it. 2. T F If a thread calls pthread cond wait() after having locked the mutex passed as an argument, when pthread cond wait() returns, the mutex will be locked. 3. T F Deadlock is a situation in which processes or threads are waiting for an event that will occur in the future. 4. T F Shortest job first with preemption always has a lower or equal wait time per process than shortest job first without preemption. 5. T F A reference to a local variable returned from a POSIX thread will be read successfully when joined. 6. T F If successful, the fork() system call returns 0 to the parent and the process ID of the parent process to the child. 7. T F A semaphore initialized with a count of 1 can be used in place of a mutex. 8. T F The sigset t parameter to sigsuspend() should include the signal which will be sent to wake the thread. 9. T F A successful implementation of priority scheduling must vary the time quantum for higher priority jobs. 10. T F The only safe way to stop a POSIX realtime timer (POSIX:TMR) is to use timer delete(). CS 241 Midterm Exam 4 NetID: 17. (a) Give an example of a deadlock. (b) What is a way to prevent circular wait amongst processes? CS 241 Midterm Exam 5 NetID: 18. (a) What is the effect of making the time slice too large or too small in a round robin scheduler? (b) Assuming all processes arrive at t=0, use round robin scheduling and a time slice of t=50ms to schedule the processes listed below: Process A requests 150ms of burst time Process B requests 60ms of burst time Process C requests 100ms of burst time (c) What is the average wait time per process in the schedule above? CS 241 Midterm Exam 6 NetID: 19. Check the following code segment and description for validity. Either justify how the segment is valid, or make necessary changes if it is invalid. The function waitForSignal() sets up a signal set containing all but SIGINT. When waitForSignal() returns, a SIGINT will have been caught by sigsuspend(). int waitForSignal() { sigset_t sigmost; int signum = SIGINT; sigfillset(&sigmost); sigdelset(&sigmost,signum); return sigsuspend(&sigmost); }