{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}


SampleFinalCS3214F09 - CS 3214 Sample Final Exam(Fall 2009...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 3214 Sample Final Exam (Fall 2009) 1/10 Sample Final Exam (Fall 2009) Solutions are shown in this style. This exam was given Fall 2009 1. System Calls (16 pts) a) (12 pts) Consider the following interaction of a user running bash in a terminal. In the table below, list the following events: (1) process-related system calls (fork, exec, exit, kill, wait/waitpid) and (2) signals delivered to a process (such as SIGCHLD, SIGINT, SIGTSTP, SIGTERM) . User input shown in bold, terminal output in italics Shell Process Child Process 1 Child Process 2 $ ls fork() exec(“ls”) exit() waitpid()/ SIGCHLD $ sleep 100 & [1] 29598 fork() exec(“sleep”) $ [2] 29599 fork() exec(“sleep”) $ jobs [1]- Running sleep 100 & [2]+ Running sleep 200 & $ fg %2 sleep 200 waitpid() User types ^C SIGINT SIGCHLD +waitpid() waitpid() $ fg %1 sleep 100 waitpid() User types ^Z SIGTSTP SIGCHLD +waitpid() [1]+ Stopped sleep 100 $ kill %1 kill() SIGTERM SIGCHLD +waitpid() $ jobs
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CS 3214 Sample Final Exam (Fall 2009) 2/10 [1]+ Terminated sleep 100 Use different rows to express if events are synchronized, i.e., if it is guaranteed that event n occurs after event m, then event n should be listed in a row below event m. Note that not all rows/columns will have entries. b) (4 pts) Explain briefly the key difference between the terms “background process” and “stopped process”! A background process is one whose process group is not currently the foreground process group of its controlling terminal (or a process that has been detached from its controlling terminal). A background process can perform computation, consume CPU time, or be blocked while doing I/O or engaging in synchronization with other processes. A stopped process is a background process that is in the stopped state – it is not scheduled by the OS onto any CPU, cannot perform computation or I/O until it is moved out of the stopped state via a SIGCONT signal or terminated. 2. Multithreading (18 pts) a) (10 pts) Consider a fixed thread pool such as the one you implemented in exercise 11. Such a thread pool creates a fixed number of threads that process submitted tasks in FIFO order. Each task (or “callable”) is represented by a C function that receives a pointer to a custom argument. /* Data to be passed to callable. */ struct callable_data { int number; sem_t *next, *previous; }; /* A callable. */ void * callable_task(struct callable_data * callable) { sem_wait(callable->previous); printf("Task %d ran.\n", callable->number); sem_post(callable->next); return NULL; } int main(…) { const int N = ntasks; sem_t s[N + 1]; // …. main continued // create N callable tasks struct callable_data * callable_data[N]; for (i = 0; i < N; i++) { callable_data[i] = malloc( sizeof *callable_data[i]); callable_data[i]->number = i; callable_data[i]->next = &s[i + 1]; callable_data[i]->previous = &s[i]; } // submit tasks to thread pool for (i = N - 1; i >= 0; i--) { printf("Submitting task %d: next=%d, previous=%d\n",
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 10

SampleFinalCS3214F09 - CS 3214 Sample Final Exam(Fall 2009...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon bookmark
Ask a homework question - tutors are online