Midterm Solution 2008
Midterm Solution 2008
OPERATING SYSTEMS
MIDTERM EXAM SOLUTION
Department of Computer Science
University of Calgary
Professor: Carey Williamson
October 29, 2008
This is a CLOSED BOOK exam. Textbooks, notes, laptops, calculators, personal digital
assistants, cell phones, and Internet access are NOT allowed.
It is a 50 minute exam, with a total of 50 marks. There are 10 questions, and 8 pages
(including this cover page). Please read each question carefully, and write your answers
legibly in the space provided. You may do the questions in any order you wish, but please
USE YOUR TIME WISELY.
When you are finished, please hand in your exam paper and sign out. Good luck!
Student Name:
Student ID:
Score:
/ 50 =
Multiple Choice
Choose the best answer for each of the following 6 questions, for a total of 6 marks.
1
2. The system calls chown(), chmod(), and umask() are examples of operating system
functionality for:
(a) file manipulation
(b) device manipulation
(c) process control
(d) information maintenance
(e) protection and security
(f) inter-process communication
5. Among CPU scheduling policies, First Come First Serve (FCFS) is attractive because:
(a) it is simple to implement
(b) it is fair to all processes
(c) it minimizes the total waiting time in the system
(d) it minimizes the average waiting time in the system
(e) it minimizes the average response time in the system
(f) it minimizes the average turnaround time in the system
6. Among CPU scheduling policies, Shortest Remaining Processing Time (SRPT) is attractive because:
(a) it is simple to implement
(b) it is fair to all processes in the system
(c) it minimizes the average waiting time in the system
(d) it minimizes the average response time in the system
(e) it minimizes the number of context switches in the system
(f) it maximizes the number of context switches in the system
7. For each of the following pairs of terms, define each term, making sure to clarify the
key difference(s) between the two terms.
(a) (2 marks) application software and system software
Both are types of software that can run on a computer system.
Application software: designed by users or 3rd party vendors for specific
problem domains (e.g., gaming, graphics, spreadsheets, word processor)
System software: operating system itself, plus support utilities (e.g.,
text editor, compiler, shell, command-line utilities)
Application software typically runs on top of system software,
but can make use of system software and OS services.
(b) (2 marks) user mode and kernel mode
These are types of execution modes in an operating system.
User mode: conventional operating mode for user apps, which
have restricted privileges for what they can do on the system
Kernel mode: provides raw access to physical hardware for the OS;
process has full privileges for what it can do on the system
System calls allow a user process to transition from user mode to kernel
mode for use of specific OS servies.
(c) (2 marks) single-core and multi-core
These are two types of architectures for processor (CPU) design.
Single core: only 1 processor on a chip; supports only 1 thread of control
Multi-core: more than 1 processor on a chip, each with own registers,
program counter, etc,; supports multiple concurrent threads of control
Multi-core provides hardware support for mutli-threaded applications.
Faster execution possible, but more complicated to design and coordinate.
(note the question is not about uniprocessors versus multi-processors)
(d) (2 marks) text segment and data segment
These are two different pieces of a typical process address space.
Text segment: stores the code that is being executed; usually immutable
Data segment: stores the statically allocated data (constants, arrays,
global variables) for the process; usually read and modified by the process
(e) (2 marks) short-term scheduler and long-term scheduler
These are two different concepts of CPU scheduling in an OS.
Short-term: decides which in-memory ready process gets the CPU next
Long-term: decides which jobs go in-memory and on the ready queue
The decision-making time scales differ (milliseconds versus seconds).
(f) (2 marks) waiting time and service time
These are two contributors to job turnaround time in CPU scheduling.
Waiting time: amount of time spent waiting your turn for the resource (CPU)
Service time: actual time spent using the resource (CPU) during your turn(s)
4
CPU Scheduling
10
8. Suppose that the following jobs arrive as indicated for scheduling and execution on a
single CPU.
Job Arrival Time Size (msec) Priority
J1
0
12
1 (Gold)
J2
2
4
3 (Bronze)
J3
5
2
1 (Gold)
J4
8
10
3 (Bronze) <(Note: typo fixed now)
J5
10
6
2 (Silver) <(Note: typo fixed now)
(a) (2 marks) Draw a Gantt chart showing FCFS scheduling for these jobs, and calculate
the average job waiting time.
J1
J2
0
J1:
J2:
10
12
J3:
11
J4:
J3
J4
16 18
J5
28
10
18
J5:
34
Avg:
49/5 = 9.8 ms
(b) (2 marks) Draw a Gantt chart showing non-preemptive SJF scheduling for these jobs,
and calculate the average job waiting time.
J1
J3
0
J1:
J2:
12
J2
J5
14 18
12
J3:
J4:
16
J5:
J4
24
34
Avg:
43/5 = 8.6 ms
(c) (2 marks) Draw a Gantt chart showing preemptive SJF (SRPT) scheduling for these
jobs, and calculate the average job waiting time.
J1
J2
0
J1:
12
J2:
2
J3:
J3
6
J4:
J1
8 10
16
J5:
J5
16
J1
24
J4
34
Avg:
29/5 = 5.8 ms
(d) (2 marks) Draw a Gantt chart showing RR (quantum = 4) scheduling for these jobs,
and calculate the average job waiting time.
J1
0
J1:
20
J2
4
J2:
J3
8
2
J4
10
14
J4:
J3:
J5
J1
18
16
J5:
J4
22
J5
28
26
12
Avg:
J1
32
J4
34
53/5 = 10.6 ms
(e) (2 marks) Draw a Gantt chart showing (preemptive) PRIORITY scheduling for these
jobs, and calculate the average job waiting time.
J1
J3
0
J1:
J2:
18
J3:
J5
J2
14 20
12
7
J4:
16
5
J5:
J4
24
4
34
Avg:
45/5 = 9.0 ms
9. The output on the next page is from a moderately busy Linux system. Use the output
and your knowledge of Linux systems to answer the following questions:
(a) (1 mark) How many users are using the system in this example?
5 users (although only 3 are distinct human users)
(b) (1 mark) On average, how many processes are currently in the ready queue?
2
(c) (1 mark) Has the system load been increasing, decreasing, or staying about the same
in the last 15 minutes?
about the same
(d) (1 mark) What type of Linux shell is the user (carey) running?
the C shell (csh)
(e) (1 mark) What is the default scheduling priority for user processes on this system?
75
(f) (1 mark) What is the PID of the most recently created process for user jsmith?
26068
(g) (1 mark) Among all the indicated processes on the system, which has consumed the
most CPU time so far?
6321 (running Xvnc)
(h) (1 mark) Which user owns the process identified in (g)?
bushay (1367)
(i) (1 mark) How many different terminal windows does the user in (h) have running?
4 pseudo-terminals (pts)
(j) (1 mark) Among all the indicated processes on the system, which process has the
largest memory footprint?
6321 (running Xvnc)
[carey@csl ~]$ w
11:38:22 up 89 days, 52 min, 5 users, load average: 2.01, 2.02, 2.00
USER
TTY
FROM
LOGIN@
IDLE
JCPU
PCPU WHAT
jsmith
pts/1
s0106001b11691c1 10:00
1:09m 0.03s 0.00s ./a.out
jsmith
pts/2
s0106001b11691c1 10:13
1:10m 0.02s 0.00s ./a.out
carey
pts/3
csg
11:38
0.00s 0.01s 0.00s w
bushay
pts/9
agren
06Oct08 20:54m 0.03s 0.03s -bash
bushay
pts/13
agren
Sat13
20:37m 0.01s 0.01s -bash
[carey@csl ~]$ ps
PID TTY
TIME CMD
28016 pts/3
00:00:00 csh
28052 pts/3
00:00:00 ps
[carey@csl ~]$ ps -l
F S
UID
PID PPID
0 S
214 28016 28015
0 R
214 28053 28016
C PRI
0 75
0 75
TIME CMD
00:00:00 csh
00:00:00 ps
ADDR SZ
- 3684
- 1059
- 2711
- 1464
- 1155
- 4330
- 1060
- 2712
- 1496
- 1154
- 2577
- 1159
- 2578
- 1192
WCHAN
-
TTY
?
?
?
?
pts/7
?
?
?
?
pts/10
?
pts/9
?
pts/13
TIME
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:22
00:00:00
00:00:00
00:00:00
00:00:00
00:00:04
00:00:00
00:00:00
00:00:00
CMD
Xvnc
vncconfig
xterm
twm
bash
Xvnc
vncconfig
xterm
twm
bash
sshd
bash
sshd
bash
ADDR SZ
- 2544
- 1406
- 2544
- 1390
380
381
WCHAN
-
TTY
?
pts/1
?
pts/2
pts/1
pts/2
TIME
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
CMD
sshd
tcsh
sshd
tcsh
a.out
a.out
10. Most modern operating systems provide support for both processes and threads.
(a) (3 marks) What is a process?
- a program in execution
- an active entity that consumes system resources
- basic unit of resource allocation in an operating system
- has identity (PID) and attributes (owner, size, priority, etc.)
- represented by a Process Control Block (PCB)
(making any 3 of these points, or similar ones, would suffice)
(b) (3 marks) What is a thread?
- a flow of control within a process
- a thread is lightweight entity (part of a process)
- has a stack and program counter of its own
- basic unit of CPU allocation in modern operating systems
(making any 3 of these points, or similar ones, would suffice)
(c) (2 marks) List two key differences between processes and threads.
- a process is heavyweight, while a thread is lightweight
- a thread is a part of a process (containment within)
- a process must have at least one thread
- a process can have multiple concurrent threads
- thread provides finer grain control for tasks, scheduling, etc.
- IPC and sharing is easier between threads than processes
(making any 2 of these points, or similar ones, would suffice)
(d) (2 marks) List two similarities between processes and threads.
- both are active entities
- both are supported on most modern operating systems
- both are examples of tasks in the Linux system
- both have many attributes (e.g., owner, parent, priority)
- both have stack space and program counter
- both require CPU scheduling in order to do their work
(making any 2 of these points, or similar ones, would suffice)
(e) (1 mark) What Linux system call is normally used for process creation?
fork()
(f) (1 mark) What Linux system call is normally used for thread creation?
clone()
(note that pthreadcreate() is not a system call)