Docsity

10 Problems on System Programming - Exam | CS 241, Exams of Computer Science

Toggle sidebar
bg1
Take-Home Review Exam
(cs423)
Problem 1: Multiple Choice Questions
[30 points]
1) (1 Point) What two advantages do threads have over multiple processes?
A.
a. Threads have separate memory space;
b. Threads don't destroy shared data;
B.
a. Threads are inexpensive to create and destroy;
b. Threads use very little resources while they exist;
C.
a. Threads don't have to {\em trust} each other;
b. Threads don't have separate memory space;
Write your answer here:____
2) (1 Point) A rendezvous requires
A. no buffering
B. double buffering
C. a buffer queue
D. none of the above
Write your answer here:____
3) (1 Point) Assume that there are four queues in a multilevel queue scheduling system:
one first-come first-served queue and three round-robin queues with quantum = 8, 16, and 32
milliseconds respectively. What is the quantum of the first-come first-served queue?
A. 8 milliseconds
B. 64 milliseconds
C. 32 milliseconds
D. none of the above
Write your answer here:____
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15

Partial preview of the text

Download 10 Problems on System Programming - Exam | CS 241 and more Exams Computer Science in PDF only on Docsity!

Take-Home Review Exam

(cs423)

Problem 1: Multiple Choice Questions

[30 points]

  1. (1 Point) What two advantages do threads have over multiple processes? A. a. Threads have separate memory space; b. Threads don't destroy shared data; B. a. Threads are inexpensive to create and destroy; b. Threads use very little resources while they exist; C. a. Threads don't have to {\em trust} each other; b. Threads don't have separate memory space;

Write your answer here:____

  1. (1 Point) A rendezvous requires

A. no buffering B. double buffering C. a buffer queue D. none of the above

Write your answer here:____

  1. (1 Point) Assume that there are four queues in a multilevel queue scheduling system: one first-come first-served queue and three round-robin queues with quantum = 8, 16, and 32 milliseconds respectively. What is the quantum of the first-come first-served queue?

A. 8 milliseconds B. 64 milliseconds C. 32 milliseconds D. none of the above

Write your answer here:____

  1. (1 Point) What is convoy effect?

A. Having one IO-bound process and {\it n} CPU-bound process B. Having mixed balance between IO bound and CPU bound processes C. Having {\it n} IO-bound processes and one CPU-bound process

Write your answer here:____

  1. (1 Point) A signal handler is useful for

A. catching SIGKILL B. specifying action to be taken for a specific signal C. changing signal from UNBLOCKED to BLOCKED signal

Write your answer here:____

  1. (1 Point) Let us assume an event (job) arriving with the constant arrival rate of 20 processes per second. Let us assume two processors with the constant service rates 20 processes per second each. What is the overall system utilization under these assumptions?

A. 100% B. 50% C. 20%

Write your answer here:____

  1. (2 Point) Consider the 2-process solution to the critical section problem (i refers to the current process and j is the other one)

repeat flag[i] := true ; while (flag[j]) do no-op ;

flag[i] := false ;

until false ;

This solution does NOT satisfy :

A Mutual Exclusion B Progress C Bounded Wait D both (b) and (c) E none of the above

Write your answer here:____

  1. (1 Point) A UNIX file system has 4-KB blocks and 4-byte disk addresses. The inode of file ‘ X ’ requires 8 direct entries and an indirect block which is half full. How large is the file in blocks?

A. 16 B. 264 C. 520 D. 1032 E. 5004

Write your answer here:____

  1. (1 Point) How many disk operations are needed to fetch the first data block of the file /a/b/c? Assume that the inode of ‘/a ’ is already in memory, but not the contents of ‘ a ’ and there are no other mount points. Assume all directory listings use one disk block.

A. 2

B. 3

C. 4

D. 5

E. More than 5

Write your answer here:____

  1. (1 Point) “Only one process may use a resource at a time” best describes which one of the following?

A. Mutual Exclusion B. Hold and wait C. No preemption D. Circular wait E. Starvation

Write your answer here:____

  1. (1 Point) “A process may hold allocated resources while awaiting assignment of other resources” best describes which one of the following conditions?

A. Mutual Exclusion B. Hold and wait C. No preemption D. Circular wait E. Starvation

Write your answer here:____

  1. (1 Point) “No resource can be forcibly removed from a process holding it” best describes which one of the following conditions?

A. Mutual Exclusion B. Hold and wait C. No preemption D. Circular wait E. Starvation

Write your answer here:____

  1. (1 Point) Which problem is avoided by defining a linear ordering of resource types that is followed by all processes?

A. Mutual Exclusion B. Hold and wait C. No preemption D. Circular wait E. Starvation

Write your answer here:____

For questions 17 and 18: Consider a simple one-level paging system with the following parameters: page size of 16 Kbytes; 64 bit logical address space; each page table entry takes 8 bytes.

  1. (1 Point) How many logical pages are there (expressed as a power of 2)?

A. 2^40 B. 2^48 C. 2^50 D. 2^52 E. 2^53

Write your answer here: ___

  1. (1 Point) In this system, how large is the page table size in bytes?

A. 2^40 B. 2^48 C. 2^50 D. 2^52 E. 2^53

Write your answer here:____

  1. (1 Point) Which one of the following is NOT stored in a disk partition?

A. Master boot record. B. Super block. C. Free-space management information. D. inode data. E. Directory names.

Write your answer here:____

  1. (1 Point) Which one of following best describes the seek time of a disk?

A. Latency of moving the disk head B. Time required to access one block from the disk C. Latency of moving the disk head plus the average rotational delay D. Latency of moving the disk head plus the maximal rotational delay

Write your answer here:____

  1. (1 Point) A 512KB file is stored contiguously on one disk track. Each track contains 1024 sectors, each sector is 512 bytes. Average seek time=1ms and rotational speed is 15,000 RPM (Rotations Per Minute). What is the average access time to read the entire file, in milliseconds? Hint: 60,000 RPM = 1 rotation per 1ms.

A. Between 0 and 1.9 ms B. Between 2.0 and 2.4 ms C. Between 2.5 and 2.9 ms D. Between 3.0 and 4.9 ms E. Between 5.0 and 10.0 ms

Write your answer here:____

  1. (1 Point) Which one of the following is NOT true under Linux?

A. A page of size 2^13 bytes implies a page offset of 13 bits. B. The TLB must be flushed during a process context switch. C. A page table converts a logical page number to a physical page number. D. Logical pages of different processes can be mapped to the same physical page. E. A TLB miss will generate a page fault.

Write your answer here:____

  1. TCP opens what kind of connection between the client and server?

A. one-way asymmetric connection B. one-way symmetric connection C. two-way symmetric connection D. two-way asymmetric connection

Write your answer here:___

END OF MULTIPLE CHOICE

SHORT ANSWER QUESTIONS FOLLOW ON THE NEXT PAGE

CS 241 Netid :__________________

Problem 3. Networking & Queuing Theory [10 Points]

3A) List and briefly explain 2 features that TCP provides that UDP does not [4 points].

i)

ii)

3B) Briefly explain one advantage of using TCP instead of UDP to perform a file transfer [ Point]

3C) Briefly explain one advantage of using UDP instead of TCP to stream video content. [ Point]

3D) Briefly explain the purpose of the TTL field in the IP header. [1 Point]

3E) An application creates a UDP packet with a ”TTL” number of 5. Under what conditions would this packet arrive at the destination? [1 Point]

3F) A web-server queues incoming HTTP requests in a FIFO queue. A new request arrives on average every 200 milliseconds. There are on average 10 requests in the queue. Use Little’s law to calculate the average response time of the web-server (please show your work). [2 Points] The formulae

/

,

1+

2, W=1/ (

), L =

W, may be useful.

CS 241 Netid :__________________

Problem 4. Virtual Memory [20 points]

4A) Define the concepts of thrashing and working set. [2Points] i)

ii)

4B.) Draw a diagram illustrating how the number of page faults per second varies as the number of pages allocated to a process changes. Indicate in the diagram an example region of thrashing and an example region for working set. [3 points]

4C) When the number of page frames is increased, the number of faults increases. What is this effect called, and which replacement policy exhibits this effect? [2 points]

This effect is called _______________________________,

And it is exhibited by the ____________________________replacement policy.

Number of pages allocated

Page fault rate

CS 241 Netid :__________________

4E) Explain why it is not possible to combine a global page replacement policy and a fixed page allocation policy. [2 Points]

4F) Describe one advantage of implementing Second Chance instead of Least Recently Used replacement policy. [1 point]

4G) Considering the answer to the multiple choice question 9 and 10, briefly explain why inverted page tables are useful for 64 bit address space? [2 Points]

4H) Describe how an address lookup is performed on an inverted page table. [2 Points]

CS 241 Netid :__________________

Problem 5. Deadlock A [10 points]

5A) What is the difference between a preemptible and a non-preemptible resource? [1 point]

5B) Briefly explain why preemption of the CPU resource requires interrupts and timers. [ point]

5C) Consider the following resource requests. Process 1 requests exclusive use of both the CPU and the display. Process 2 requests exclusive use of both the display and the disk. Process 3 requests exclusive use of both the disk and the network. Process 4 requests exclusive use of both the network and the display. Resources are assigned in process request order (Process 1 is first). The disk, display and network resources are non-preemptible. Determine if deadlock is possible by constructing a Resource Allocation Graph and a Wait-For graph. [4 points]

i) Resource Allocation Graph: ii) Wait-for-Graph:

CS 241 Netid :__________________

Problem 6. Deadlock B [5 points]

6A) Consider the following three threads executing different paths of execution. Determine if and where deadlock can occur for each thread. For example, “Thread 1 can deadlock on Line 2” would mean that Thread 1 can deadlock and wait forever to acquire mutex_e. [3 points]

Line Thread 1 Thread 2 Thread 3 1 lock(mutex_d) lock(mutex_e) lock(mutex_f) 2 lock(mutex_e) lock(mutex_f) lock(mutex_d) 3 e = d * 2 f = f + e d = d * f 4 unlock(mutex_e) unlock(mutex_f) unlock(mutex_d) 5 unlock(mutex_d) unlock(mutex_e) unlock(mutex_f)

Complete the following, or write deadlock cannot occur

Thread 1 can deadlock on line ___

Thread 2 can deadlock on line ___

Thread 3 can deadlock on line ___

6B) Determine if and where deadlock can occur. [2 points] Thread 1 Thread 2 1 lock(mutex_h) lock(mutex_g) 2 lock(mutex_i) lock(mutex_i) 3 lock(mutex_j) i = g + g 4 j = i + h unlock(mutex_i) 5 unlock(mutex_j) unlock(mutex_g) 6 unlock(mutex_h) 7 lock(mutex_g) 8 g = g + i 9 unlock(mutex_g) 10 unlock(mutex_i)

Complete the following, or write deadlock cannot occur

Thread 1 can deadlock on line ___

Thread 2 can deadlock on line ___

CS 241 Netid :__________________

Problem 7. File system [5 points]

7A.) Determine the reference count of the disk inode associated with file ‘ f1 ’ and ‘ f2 ’ after the following set of shell commands. Files do not exist prior to the execution of the following commands. The commands complete successfully (without errors). [2 Points]

1> echo “hello CS241” > f 2> ln –s f1 f 3> ln f2 f 4> ln f1 f 5> rm f

final reference count for f1 = ____

final reference count for f2 = ____

7B.) In the above example, which is the last line that modifies the inode update time for f1? [1 point]

Give the line number: ________

7C. ) A process reads all bytes of a 2^20 byte file '/tmp/s/g1 '. g1 is a soft link to file g2 in the same directory. If reading the directory entries of /tmp is the first block read, how many blocks in total must be read?

Assume each directory’s listing fits into one block , a block size is 2^12 bytes and we deal with a standard inode-based file-system where the first 10 blocks are referenced directly and a block pointer requires 4 bytes. Assume after the first time a block is read or written, its contents are cached in memory. [2 points]

CS 241 Netid :__________________

Problem 9. Network Implementation [10 points]

Complete the C code below to set up a TCP server socket with a backlog of 8 connections, and wait for a connection. Store the connection socket in the variable ' conn_sock '. The following constants and functions may be useful. The server socket address is provided as an argument ‘addr’. You do not need to include error handling or use any fields of any structures. Assume that there is additional code after your block of code that uses 'conn_sock '.

// constants: AF_INET, PF_INET, SOCK_DGRAM, SOCK_STREAM int accept(int s, struct sockaddr *addr, socklen_t *addrlen); int bind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen); int connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen); int listen(int s, int backlog); int socket(int domain, int type, int protocol);

void server(struct sockaddr_in *addr)

{

int conn_sock;

// write your code here

CS 241 Netid :__________________

Problem 10. Synchronization [20 points]

Consider the following code:

Lock mutex;

mutex.acquire();

shared variable accessed

mutex.release();

  1. (14 Points) Write a pseudo-code to define Lock structure and the procedures acquire, release, applying swap hardware synchronization mechanism. Note that the swap routine is defined as follows:

void swap(char *x, y) { char temp; temp=x; *x = *y; *y = temp; }

  1. (6 Points) Explain why your implementation enforces mutual exclusion.

END OF EXAM

Check your answers.

Check your Netid is on every sheet.

Check your Problem 1 responses are written on the Right

Hand Side.

You can use this sheet for scratch paper, or for overflow.