Edition with Verified Questions & Solutions!
What are the two main functions of an operating system? - An operating system must provide the
users with an extended machine, and it must manage the I/O devices and other system resources.
What is the difference between kernel and user mode? - In Kernel mode, the executing code has
complete and unrestricted access to the underlying hardware. In User mode, the executing code has
no ability to directly access hardware. Code running in user mode must delegate to system APIs to
access hardware.
What is a trap instruction? Explain its use in operating systems? - A trap instruction switches the
execution mode of a CPU from the user mode to the kernel mode. This instruction allows a user
program to invoke functions in the operating system kernel.
What is multiprogramming? Give 2 reasons for having it. - Having multiple programs resident at once
and having them all active at the same time. Only one runs at any instant, but they may each run in
turn. This increases CPU utilization, decreases response and turnaround time. While one program is
waiting for I/O, another can be using the CPU.
Which of the following instructions should be allowed only in kernel mode?
A. disable all interrupts
B. read the time of day clock
C. set the time of day clock
D. change the memory map - (O)A. Kernel mode only. Obvious
(X)B. Doesn't need to be done only in kernel mode
(O)C. Needs to be done only in kernel mode otherwise, a job could set the clock back to increase its
processor time slice (among other things)
(O)D. Kernel mode only. Obvious
Please name two advantages to decouple a process address space from the machine's physical
memory in modern operating system design. - This allows an executable program to be loaded in
different parts of the machine's memory in different runs. Also, it enables program size to exceed the
size of the machine's memory.
,What's different between the concepts: process and program? - A process is basically a program in
execution.
What is the purpose of the cache? - Improving performance by storing frequently-read data in a
small portion of memory rather than waiting for the application to access the same data from the
main memory.
How many times does the following program print hello?
#include <stdio.h>
#include <unistd.h>
main()
{
int i;
for (i=0; i<3; i++)
fork();
printf("hello\n");
} - 8 Times
fork (); // Line 1
fork (); // Line 2
fork (); // Line 3
L1 // There will be 1 child process
/ \ // created by line 1.
L2 L2 // There will be 2 child processes
/ \ / \ // created by line 2
L3 L3 L3 L3 // There will be 4 child processes // created by line 3
To implement a user-level threads package, it helps if the operating system provides: - Non-blocking
system calls.
Starvation is the case when a thread: - Is never scheduled to run.
, A thread that is blocked on a semaphore is awakened when another thread: - Tries to increment the
semaphore.
The POSIX execve system call creates a new process. - False.
The exec() family of functions replaces the current process image with a new process image. It loads
the program into the current process space and runs it from the entry point.
Switching among threads in the same process is more efficient than switching among processes. -
True.
1. Thread Switching :Thread switching is a type of context switching from one thread to another
thread in the same process. Thread switching is very efficient and much cheaper because it involves
switching out only identities and resources such as the program counter, registers and stack pointers.
The cost of thread-to-thread switching is about the same as the cost of entering and exiting the
kernel.
2. Process Switching :Process switching is a type of context switching where we switch one process
with another process. It involves switching of all the process resources with those needed by a new
process. This means switching the memory address space. This includes memory addresses, page
tables, and kernel resources, caches in the processor.
Using mutual exclusion can ensure that a system avoids deadlock. - False.
Process P1 holds resource R1 and waits for resource R2 which is held by process P2.
Process P2 holds resource R2 and waits for resource R1 which is held by process P1.
None of the two processes can complete and release their resource.
Thus, both the processes keep waiting infinitely.
The value of a semaphore can never be negative. - True
A race condition is - When the outcome of processes is dependent on the exact order of execution
among them.
The wait system call on UNIX systems puts a process to sleep until: - A child process terminates.