Midterm 1
Imagine the following four processes are running on a system with a single CPU. The columns of this table show how much CPU time each process needs for its next CPU burst and when the process arrives in the ready queue. (it's the same table as in the previous question). ProcessCPU Burst LengthArrival Time P1 5 0 P2 6 3 P3 3 4 P4 1 6 If these processes are scheduled using FCFS, what will their average waiting time be? Select one: a. 4.0 b. 3.5 c. 4.25 d. 3.25 e. 3.75
C
Which are the three different ways the CPU can go from user mode to kernel mode? Select one or more: a. software error b. privileged instruction c. return-from-trap instruction d. hardware interrupt e. dual-mode operation f. system call
A, D, F
A process has the following four memory regions. Which of these will typically be read-only? Select one: a. The data section b. The stack c. The text section d. The heap
C
Which of these best describes a difference between user-level and kernel-level threads running inside the same process? Pick the best answer. Select one: a. User-level threads can share stack space, but kernel-level threads each need their own stack. b. User-level threads each have a different heap and data section, but kernel-level threads can share these. c. Kernel-level threads require a system call to create a new thread, but user-level threads can make a new thread with a subroutine call. d. The maximum number of kernel-level threads is limited to the number of CPU cores, but a process can have any number of user-level threads.
C
What are shared by threads? Select two answers that apply. Select one or more: a. Stack b. Program Counter c. Heap d. Opened files
C, D
Imagine the following four processes are running on a system with a single CPU. The columns of this table show how much CPU time each process needs for its next CPU burst and when the process arrives in the ready queue. ProcessCPU Burst LengthArrival Time P1 5 0 P2 6 3 P3 3 4 P4 1 6 If these processes are scheduled using FCFS, what will their average turnaround time be? Select one: a. 9.5 b. 10.0 c. 9.0 d. 8.5 e. 8.0
E
The Process Control Block does NOT contain: Select one: a. open file content. b. program counter value. c. process state. d. process ID.
A
Which of the following system calls gets the operating system to put a shared memory segment in a process' address space? Select one: a. shmat() b. shmget() c. shmdt() d. shmctl()
A
When does the operating system save copies of all the CPU registers for a process? Select one: a. Whenever a process terminates. b. Whenever a process transitions from the waiting state to the ready state. c. During a context switch. d. Whenever the system is powered down. e. Whenever a new process is started.
C
If these processes are scheduled using Preemptive Priority, what will their average waiting time be? ProcessCPU Burst LengthArrival TimePriority P1 8 0 7 P2 6 3 8 P3 4 5 6 P4 3 7 4 Select one: a. 4.75 b. 4.25 c. 5.0 d. 5.5 e. 4.5
D
If you're using POSIX threads, what happens when a thread returns from its start routine? Select one: a. That thread goes back to the top of its start routine and continues executing from there. b. That thread returns back to main() and resumes executing there. c. Threads can't return from their start routine. Instead, they have to call pthread_join() to wait until other threads are finished. d. That thread terminates.
D
After creating an anonymous pipe, how can a process send a message via the pipe? Select one: a. The process can store any integer value in the file descriptor for the writing end of the pipe. b. There's a send() system call for sending messages. c. It can use the read() system call. d. It can use the write() system call.
D
For load balancing, the Linux CPU scheduler will occasionally need to move processes among the CPU cores. Otherwise, it tries to always run every CPU burst of a given process on the same CPU core. This is an effort to provide Select one: a. Soft processor affinity b. Symmetric multiprocessing c. Hard processor affinity d. Asymmetric multiprocessing
A
Consider the system call used to create an anonymous pipe. What parameters does this system call take? Select one: a. An array, with room for two file descriptors. b. A unique integer and one or more flags. c. A string containing a unique name. d. It doesn't take any parameters.
A
Between the two types of communications models, POSIX anonymous pipe is an example of message passing but not shared memory. Select one: True False
TRUE
How is a trap different from a hardware interrupt? Choose the best answer. Select one: a. A trap is caused by an instruction in the program that's running. b. After the handler finishes executing, a trap never returns to the previously running program. c. When a trap occurs, the CPU jumps to a handler in the user program, rather than in the OS. d. A trap is caused by the operating system.
A
Imagine the following four processes are running on a system with a single CPU. The columns of this table show how much CPU time each process needs for its next CPU burst, when the process arrives in the ready queue and its priority (assume lower numbers represent higher-priority processes). ProcessCPU Burst LengthArrival TimePriority P1 8 0 7 P2 6 3 8 P3 4 5 6 P4 3 7 4 If these processes are scheduled using (non-preemptive) Priority, what will their average waiting time be? Select one: a. 4.75 b. 4.0 c. 5.5 d. 5.0 e. 4.5
A
To directly access the services of the operating system, the interface is provided by the __________. a. Library b. System calls c. Assembly instructions d. CPU
B
When using POSIX threads, a thread's start routine takes just one parameter. How do you pass in a value for this parameter? Select one: a. When you call the start routine from main(), you can provide a value for this parameter. b. The last parameter to pthread_create() is passed in to the start routine. c. You can't provide a value for this parameter. It's automatically set to null for the first thread that's created. For each subsequent thread, it's a pointer to a handle for the most recently created thread. d. You can't pass in a value for this parameter. The operating system uses this parameter to give the thread a pointer to its own thread handle.
B
In the bounded buffer producer consumer problem, when does a thread block? Select one or more: a. when it's trying to consume an item and the buffer is full. b. when it produced an item and the buffer is full. c. when it produced an item and the buffer is empty. d. when it's trying to consume an item and the buffer is empty.
B, D
During the execution of the following program (assuming no failures), how many different values from getpid() will be printed? int main(int argc, char *argv[]){ int rc = fork(); if (rc < 0) { fprintf(stderr, "fork failed\n");exit(1);} else printf("hello, I am (pid:%d)\n", (int) getpid());rc = fork(); if (rc < 0) { fprintf(stderr, "fork failed\n"); exit(1); } else printf("hello, I am (pid:%d)\n", (int) getpid()); return 0; } a. 6 b. 8 c. 4 d. 2 e. 9
C
When using POSIX semaphores, what's the difference between sem_init() and sem_open()? Select one: a. You have to call sem_open() first, to make a semaphore, then you have to call sem_init() on that semaphore before you can use it. b. sem_init() works with a pointer to a semaphore, while sem_open() expects a copy of a whole semaphore as a parameter. c. sem_init() is used for making new semaphores, while sem_open() is for accessing semaphores that have already been created. d. sem_init() is for making semaphores that will be used between threads in the same process, while sem_open() is for semaphores that will be used between processes.
D
Which of the following is correct regarding operating system? a. Operating system is a system service provider to the application programs. b. Operating system is an interface between the hardware and application programs. c. Operating system is a collection of programs that manages hardware resources. d. All of the mentioned.
D
During the execution of the following program (assuming no failures), how many lines will be printed? int main(int argc, char *argv[]){ int rc = fork(); if (rc < 0) { fprintf(stderr, "fork failed\n");exit(1);} else printf("hello, I am (pid:%d)\n", (int) getpid());rc = fork(); if (rc < 0) { fprintf(stderr, "fork failed\n"); exit(1); } else printf("hello, I am (pid:%d)\n", (int) getpid()); return 0; } Select one: a. 8 b. 4 c. 9 d. 2 e. 6
E
What normally causes some process, P, to switch from the running state to the waiting state? Select one: a. Some other process sends a signal to P. b A I/O operation previously requested by P is completed. c. Some other process terminates (i.e., enters the terminated state). d. Some other process starts running (i.e., enters the new state). e. Process P makes a system call asking for I/O.
E
Which of these system calls causes a process to run a different program? Select one: a. _exit() b. wait() c. open() d. fork() e. execl()
E
Consider the dining philosophers problem pictured below. For this problem, what is the maximum number of philosophers who can think at the same time and the maximum number who can eat at the same time? (9 chairs in a circle) Select one: a. 9 can think and 9 can eat. b. 6 can think and 4 can eat. c. 6 can think and 3 can eat. d. 9 can think and 1 can eat. e. 7 can think and 3 can eat. f. 9 can think and 4 can eat. g. 7 can think and 1 can eat. h. 1 can think and 9 can eat.
F
A context switch happens on every timer interrupt. Select one: True False
FALSE