DOC PREVIEW
U of I CS 241 - Midterm Examination

This preview shows page 1-2-3 out of 9 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

University of Illinois at Urbana-ChampaignDepartment of Computer ScienceMidterm ExaminationCS 241 System ProgrammingFall 200511-11:50 am Monday October 171103 Siebel CenterName:NetID:• Print your name and netid neatly in the space provided above; print your netid at the upperright 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, progressto 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 Score1-10 2011-15 1016 1017 1018 1019 1020 1021 10Total 90CS 241 Midterm Exam 1 NetID:I. [True/False]Circle your answer to the left of each statement. Each correct answer in this section will beawarded 2 p oints. 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, allthreads will have access to it.2. T F If a thread calls pthread cond wait() after having locked the mutex passedas 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 anevent that will occur in the future.4. T F Shortest job first with preemption always has a lower or equal wait timeper process than shortest job first without preemption.5. T F A reference to a local variable returned from a POSIX thread will be readsuccessfully when joined.6. T F If successful, the fork() system call returns 0 to the parent and the processID 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 whichwill be sent to wake the thread.9. T F A successful implementation of priority scheduling must vary the timequantum for higher priority jobs.10. T F The only safe way to stop a POSIX realtime timer (POSIX:TMR) is touse timer delete().CS 241 Midterm Exam 2 NetID:II. [Multiple Choice]Circle the best answer to each question. Each correct answer in this section will be awarded2 points. There is no penalty for incorrect answers.11. Which synchronization construct is best used by cooperating processes to block until allprocesses reach a particular point?(a) mutex(b) semaphore(c) monitor(d) barrier12. Which scheduling method always prevents starvation?(a) FIFO(b) SJF(c) SJF with preemption(d) Priority13. Which approach does not succeed in preventing deadlocks?(a) If a process wants a set of resources throughout its execution, it must request all ofthem first.(b) If a process wants to acquire any resource, it must alert other processes not toacquire that resource.(c) When a process requests a resource that is unavailable, it must drop all resourcescurrently held.(d) Spool access to any shared resources, such as printers, and disk access.14. Which signal cannot be caught or ignored?(a) SIGINT(b) SIGFPE(c) SIGSTOP(d) SIGTERM15. Which function can be used to get the current sys tem time?(a) localtime()(b) time()(c) ctime()(d) asctime()CS 241 Midterm Exam 3 NetID:III. [Short Answer]16. (a) What is errno?(b) What problem(s) can arise w ith using errno in a multithreaded program?(c) How does POSIX address these problems?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 robinscheduler?(b) Assuming all processes arrive at t=0, use round robin scheduling and a time slice oft=50ms to schedule the processes listed below:Process A requests 150ms of burst timeProcess B requests 60ms of burst timeProcess 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 thesegment is valid, or make necessary changes if it is invalid.The function waitForSignal() sets up a signal set containing all but SIGINT. WhenwaitForSignal() 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);}CS 241 Midterm Exam 7 NetID:20. (a) List and explain briefly the four requirements for synchronization.(b) Which of the above requirements does the following pseudocode satisfy?while (true){ while (turn != my_process_id) { };Access shared variables; // Critical Sectionturn = other_process_id;Do other work}CS 241 Midterm Exam 8 NetID:21. The function signalHandler() below is prop e rly initialized with a sigaction() call to handleSIGINT. However, the code has a substantial flaw. What is it?pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;static int sharedVar = 0;void signalHandler(int, siginfo_t*, void*){fprintf(stderr,"Received signal.\n");pthread_mutex_lock(&mutex);sharedVar = sharedVar + 1;fprintf(stderr,"Signal handler has been called %i times.\n",


View Full Document

U of I CS 241 - Midterm Examination

Documents in this Course
Process

Process

28 pages

Files

Files

37 pages

File I/O

File I/O

52 pages

C Basics

C Basics

69 pages

Memory

Memory

23 pages

Threads

Threads

14 pages

Lecture

Lecture

55 pages

C Basics

C Basics

24 pages

Signals

Signals

27 pages

Memory

Memory

45 pages

Threads

Threads

47 pages

Threads

Threads

28 pages

LECTURE

LECTURE

45 pages

Threads

Threads

30 pages

Threads

Threads

55 pages

Files

Files

37 pages

SIGNALS

SIGNALS

22 pages

Files

Files

37 pages

Threads

Threads

14 pages

Threads

Threads

13 pages

Load more
Download Midterm Examination
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Midterm Examination and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Midterm Examination 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?