Midterm 2010
-
Upload
vikram-bhuskute -
Category
Documents
-
view
219 -
download
0
description
Transcript of Midterm 2010
-
CS 3305: Operating Systems
Department of Computer Science
The University of Western Ontario
Midterm Quiz
Fall, 2010
NAME : __________Answers__________________________
STUDENT NUMBER : _____________________
This is a closed book exam. You have 100 minutes to complete 24 questions. Please
write neatly and clearly. You should have 9 pages.
Question Grade
1-20 ____/43
21 ____/20
22 ____/8
23 ____/17
24 ____/12
Total ____/100
Score : ___________/ 100
-
1. (2 points) When a process is created using the classical fork() system call, which of the following is inherited by the child process?
a) Same position in code b) Process identifier c) Open files d) None of the above e) All of the above
Answer: (a) or (c) were accepted
2. (2 points) The text segment of a process address space contains: a) The statically allocated data associated with the process b) The dynamically allocated data associated with the process
c) The machine instructions d) None of the above e) All of the above
3. (2 points) If a semaphore is initialized to 5 then how many processes can be in the critical section?
a) 1 b) 2 c) 3 d) 4 e) 5
4. (2 points) Which operating system is to be modified in Assignment 2? a) Linux b) Windows XP c) Windows 7 d) Solaris e) Minix
5. (2 points) Assume process A opens file a.txt and then forks process B. Can B read a.txt?
a) Yes b) No
6. (2 points) Assume process A forks process B and then opens file a.txt. Can B read a.txt?
a) Yes b) No
7. (2 points) Can an executable have multiple processes? a) Yes b) No
-
8. (2 points) The exec family of functions allow us to run another program temporarily and return back to the original program.
a) True b) False
9. (2 points) The context switch overhead of a thread is more than the context switch overhead for a process.
a) True b) False
10. (2 points) Java is a language that is popular for writing system calls. a) True b) False
11. (2 points) A process goes from running to ready when fread(...) is called. a) True b) False
12. (2 points) A process goes from running to ready when a time quantum expires. a) True b) False
13. (2 points) I/O-bound processes should be given higher priority than CPU-bound processes in order to make more efficient use of the CPU.
a) True b) False
14. (2 points) All computers must have at least two CPUs, since the operating system needs to execute at the same time as user programs.
a) True b) False
15. (2 points) The purpose of an operating system is to manage system resources.
a) True b) False
16. (2 points) A process is a compiled version of a program. a) True b) False
-
17. (2 points) Information that can be maintained in a process control block includes the following:
a) Process identifier b) Program counter c) Pointers to open files d) a,b e) a,b,c
18. (2 points) Among CPU scheduling policies, First Come First Serve (FCFS) is attractive because:
a) It is simple to implement b) It minimizes the total waiting time in the system c) It minimizes the average waiting time in the system d) It minimizes the average response time in the system e) None of the above f) All of the above
19. (2 points) In a system where round robin is used for CPU scheduling, the following is true when a process cannot finish its computation during its current time quantum.
a) The process will terminate itself b) The process will be terminated by the operating system c) The processs state will be changed from running to ready d) The processs state will be changed from running to blocked e) None of the above
20. (5 points) The following algorithm is proposed to solve the critical section problem between two processes P1 and P2, where lock is a shared variable.
P1 P2
do { do {
while (lock); while(lock);
lock = TRUE; lock = TRUE;
critical section; critical section;
lock=FALSE; lock=FALSE;
remainder section; remainder section;
}while(TRUE); } while (TRUE);
Which of the following statements is true regarding the proposed algorithm?
a) Mutual exclusion to the critical section is guaranteed b) Both processes can be in their critical section at the same time c) Lock should be initialized to TRUE d) None of the above
-
21. (20 points) Processes, fork, pipes
a) (5 points) How many processes are created by the following program?
1 int main(void){
2 pid = fork();
3 if (pid != 0)
4 fork();
5 fork();
}
Answer: 6
You start the executable up. This creates one process. Lets call this P0. P0 executes line 1. This creates a child process. Lets call this P1. Only P0 executes line 4 which results in the creation of a new process. Lets call this P2. P0, P1,P2 each execute line 5. The result is 3 new processes. Lets call these P3, P4, P5. The total number of processes created is 6.
b) (3 points) Consider the following program. A pipe is created with the pipe
system call. A pipe is shared memory that can be read from and written to. File
descriptors, one for writing (at index 1) and one for reading (index 0), are used. What
should the values be at the question marks on lines A and B?
#include
#include
int main(void){
int n;
int fd[2];
pid_t pid;
char line[80];
if (pipe(fd) < 0)
perror("pipe error");
if ((pid = fork()) < 0) {
perror("fork error");
} else if (pid > 0) {
close(fd[?]); /*Line A*/
write(fd[?], "hello world\n", 12); /* Line B*/
}
-
Line A:___________0____ Line B: ________1_______
c) (6 points) Consider the following program. Assume that the contents of
foobar1.txt is 2 1 3 4 where each number is on a separate line. What are the contents
of foobar2.txt when the program finishes executing?
int main(void){
int fd1,fd2;
char *prog1_argv[4];
prog1_argv[0] = "sort";
prog1_argv[1] = NULL;
fd1 = open("foobar1.txt", O_RDWR);
fd2 = open("foobar2.txt", O_RDWR|O_CREAT);
dup2(fd1,STDIN_FILENO);
dup2(fd2, STDOUT_FILENO);
execvp(prog1_argv[0], prog1_argv, NULL);
exit(0);
}
Answer:
1
2
3
4
d) (6 points) In the following program, what will be the output at Lines A and B?
#include
#include
#include
int value = 5;
int main()
{
pid_t pid;
pid = fork();
if (pid == 0) { /* child process */
value = value + 15;
printf(CHILD: value = %d, value); /* Line A */
}else if (pid > 0) { /* parent process */
wait (NULL);
-
printf(PARENT: value = %d, value); /* Line B */
exit(0);
}
}
}
Line A:________20_______ Line B: _______5________
Note: We note that value is initialized to 5. During a fork each of the parents
variables are copied to be used by the child. In this program the child adds 15 to its
copy. The parent does not.
22. (8 points) System Calls
a) (2 points) What are system calls and how are they used?
Answer: A system call allows a process to request the use of OS services.
b) (4 points) What is the role of a system call handler table?
Answer: Each system call corresponds to a task. Each of these tasks is identified a
number. An entry in the system call handler table consists of a number and a pointer to
code to be executed.
c) (2 points) What is the purpose of a trap?
Answer: A trap is used to switch from user to supervisor mode.
23. (17 points) Multiprogramming and Scheduling
-
a) (5 points) Assume a multi-level scheduler. Why would it be feasible to give the
highest priority queue the smallest time quantum?
Answer: I/O bound processes spend most of their time waiting for data. When the
CPU is needed it is feasible to give I/O bound processes highest priority. Why is it
important that the time quantum be the smallest? It is important to determine the
nature (CPU-bound or I/O bound) of the process. This is not typically known in
advance. If a CPU bound process is assigned to the highest-priority queue then it is
likely to consume the short time quantum. This is a good indicator that the process is
CPU-bound. CPU-bound processes are given a lower priority and will not compete
with I/O bound processes for the highest priority queue.
b) (3 points) What is a disadvantage of the Shortest-Job First Scheduling algorithm?
Answer: One of these answers was accepted: Starvation and the difficulties in
estimating the time.
c) (3 points) Which operating system has a scheduler that is more concerned about
user perceived performance: Windows XP or Solaris?
d) (6 points) Assume round robin scheduling where the time quantum is q. How
would you estimate that a process is currently CPU bound?
Answer: The process uses all of the time quantum.
24. (12 points) Assuming no context switching time, the following table consists of a set
of jobs to be processed on a single CPU.
Job Burst
Time
Arrival
Time 1 10 0
2 1 1
-
3 2 2
4 1 3
a) (4 points) If a round-robin scheduling algorithm with a time slice of 2
milliseconds is assumed, then at approximately what time is job 3 completed?
Answer:
Timeline: t0 t1 t2 t3 t4 t5
J1 J1 J2 J3 J3
Job 1 arrives at time t0 and executes for 2 time units. Job 2 is already in the system an
executes for one time unit. When it completes Job 3 executes for 2 time units which is
sufficient for Job 3 to finish.
b) (4 points) Compute the waiting time of job 2 assuming that the scheduling policy
is first-come first serve.
Answer: It waits for 9 time units before it executes. If you assumed that waiting time
means until the job is completed then the answer is 10. Both answers were accepted.
c) (4 points) What is the order of process execution assuming that the scheduling
policy is shortest-job first, there is no pre-emption and no requests for I/O?
Answer: 1 2 4 3