Quiz
Kernel and user mode: CPU cycles, boot and interrupts
Create a free account to finish this quiz
Save your progress and see your final score.
Already have an account? Sign in
Questions in this quiz (129)
1A single CPU cycle has 3 units: Fetch, Decode, and Execute
- ATrue
- BFalse
2A single CPU cycle has 2 units: Fetch and Execute
- ATrue
- BFalse
3Pipelining CPU operations:
- Awhile executing N, decode N+1, fetch N+2
- Bwhile decoding N, execute N+1, fetch N+2
- Cwhile fetching N, decode N+1, decode N+2
4CPU Pipelining: fetch, decode, and execute are all interdependent and in series
- ATrue
- BFalse
5Which of the following answer(s) are true?
- Acache hit: the data needed by the CPU is in the cache
- Bcache miss: CPU needs to fetch the data from main memory
- Ccache hit: CPU needs to fetch the data from main memory
- Dcache miss: the data needed by the CPU is in the cache
6Kernels, just as any other app, don't have access to hardware.
- ATrue
- BFalse
7On boot, Kernel is the first thing started
- ATrue
- BFalse
8BIOS is the first stage of boot
- ATrue
- BFalse
9Kernel gets loaded and started by the bootloader
- ATrue
- BFalse
10User mode does not have all instructions available
- ATrue
- BFalse
11Only kernel and some drivers can run in kernel mode
- ATrue
- BFalse
12User mode can see the state of the CPU
- ATrue
- BFalse
13Some applications can run in kernel mode, with restrictions
- ATrue
- BFalse
14Which are in user mode?
- Acompilers
- Bkernel
- Csystem calls
- Dinterrupts
- EGUIs
- Fassemblers
15Running in root is still running in User mode.
- ATrue
- BFalse
16The OS and the kernel are separate.
- ATrue
- BFalse
17Illegal instructions in User mode result in traps (interrupts). They are then handled in Kernel mode.
- ATrue
- BFalse
18user mode invokes a special type of interrupt called a trap, to switch from user mode to kernel mode.
- ATrue
- BFalse
19In pipelined CPU: For 100 instructions, it will take an average of 1003 units to execute. (each instruction will take 3 units to execute. (N+3 unit)
- ATrue
- BFalse
20Parallel FDE:
1s Fetch ---> 1s Decode ---> 1s Execute- A3s
- B1s
21Non-parallel FDE:
1s Fetch ---> 1s Decode ---> 1s Execute- A1s
- B3s
22Are device drivers part of the OS?
- ANo, but are used by the OS (as if they were: they must be in privileged mode). Unless they can run in kernel mode (newer systems), then yes.
- BYes, they run alongside the kernel.
23Interrupts tell the CPU to do something else instead of waiting for the device to be done. Then the CPU enters Kernel mode.
- ATrue
- BFalse
24What does a CPU do when it receives an interrupt?
- Aenters kernel mode
- Benters user mode
- Csaves the state of the registers
- Dloads the state of the registers afterwards
- Enotifies the program that it has been interrupted
25There are two types of interrupts: hardware and software
- ATrue
- BFalse
26Software interrupts are an only from the CPU (anything else sending an interrupt is considered a hardware interrupt)
- ATrue
- BFalse
27Interrupts cannot interrupt other interrupts
- ATrue
- BFalse
28Types of kernels
- Amonolithic kernel
- Bmicrokernel
- Chybrid kernel
- Dmacrokernel
- Etrilithic kernel
- Fdual kernel
29Larger kernels have more bugs and therefore have more instability
- ATrue
- BFalse
30code runs faster not in kernel
- ATrue
- BFalse
31Which of following are true about microkernels?
- Aonly essentials in the kernel
- Bmore prone to bugs
- Cless bugs because of running kernel mode
- Deasier to port
- Efastest running design
- Fslower, it needs to switch modes for some things and save states
32Kernel modules are small bits of the kernel that are to be loaded in on demand. Linux only loads in the drivers it needs, leading to a much faster boot
- ATrue
- BFalse
33Any popular service on the internet actually runs on a virtual machine.
- ATrue
- BFalse
34VMs are aware that they are virtual and not physical machines
- ATrue
- BFalse
35VM cannoy talk to each other
- ATrue
- BFalse
36A hypervisor runs the VMs on either bare-metal, hosted, or hybrid.
- ATrue
- BFalse
37Benefits of VMs
- Asaves money
- Bdamage on one VM cannot damage another one
- Ccan run conflicting apps on same physical machine
- Dable to buy many smaller servers
- Eviruses infect all VMs on the hypervisor
- Fwhen a new server is requested it can be created by software from a remote location rather than physically installing a new computer as a new server
38A system call is a request to switch to kernel mode for a predefined kernel routine
- ATrue
- BFalse
39System calls are implemented as library calls
- ATrue
- BFalse
40I/O are not system calls
- ATrue
- BFalse
41a kernel can be thought of as a really big library for system calls.
- ATrue
- BFalse
42system calls are implemented in assembly and higher level wrappers utilize them
- ATrue
- BFalse
43Wrappers reduce portability between systems
- ATrue
- BFalse
44Making system calls is expensive, but making library calls is cheap
- ATrue
- BFalse
45"write()" is wrapper for system call 4
- ATrue
- BFalse
46Which of these system calls send a signal?
- Akill()
- Bsignal
47signal() system call is used to send signals
- ATrue
- BFalse
48fork() is used to duplicate a process on linux
- ATrue
- BFalse
49bash: strace is used to see every system call that was used
- ATrue
- BFalse
50
A process is a program in execution. It can be thought of as a container that holds all info needed by the OS to run a program- ATrue
- BFalse
51A pipe takes the output of the first one and makes it the input of the second one
- ATrue
- BFalse
52Multiprogramming and multitasking: Which of the following are true?
- Amultiprogramming - OS gives the CPU to another program if the current program must wait on I/O
- Bcooperative multitasking - programs get forced to yield the CPU
- Ccooperative multitasking- programs volunteer to yield the CPU
- Dpreemptive multitasking - a program gets a fraction of a second to execute, then OS switches to the next program.
- Epreemptive multitasking - a program decides when OS switches to the next program.
- Fmultithreading - even more efficient form of multitasking, usually preemptive
53Multitasking is usually just an illusion of parallelism
- ATrue
- BFalse
54Each process gets its own address space in memory
- ATrue
- BFalse
55PCB is a Process Control Block, in this course
- ATrue
- BFalse
564 examples of a PCB:
- Aprogram counter
- Bstack pointer
- Cheap reference
- Dprocess start time
- Enetwork IP
- Fkernel version
- GCPU time used
57Doing fork() will duplicate a process. Ex: an output will appear twice after the fork() line
- ATrue
- BFalse
58printf() is buffered on most linuxes and should never have outputs "overlap"
- ATrue
- BFalse
59forks spawn 2^n processes, where "n" is the number of fork calls.
- ATrue
- BFalse
60context switch is an essential feature of any multitasking OS, it allows the illusion of sharing of a single CPU (or limited number of CPUs) among many processes
- ATrue
- BFalse
61Context Switches: when OS switches between processes A and B:
- AOS first saves A's state in A's PCB
eg. save current CPU registers into PCB_A
OS then restores B's state from B's PCB
eg. load CPU registers from PCB_B - BOS first restores A's state in A's PCB
eg. save current CPU registers into PCB_A
OS then storesB's state from B's PCB
eg. load CPU registers from PCB_B
- AOS first saves A's state in A's PCB
62context switch occurs in kernel mode
- ATrue
- BFalse
63Unix signals are:
- Aa form of interprocess communication (IPC)
- Bsimilar concept to hardware interrupts on CPUs (you can think of it as software interrupts)
- Csignals are asynchronous
- Dvery limited IPC - the message is a single number, from a set of predefined integers
- Esignals are synchronous
64<ctrl-c> in a terminal will deliver SIGINT(2) to the running process
SIGINT can be caught, ignored or blocked- ATrue
- BFalse
65<ctrl-z> in a terminal will deliver SIGSTOP(2) signal to the running process
can be caught, ignored or blocked, dflt. handler suspends to process- ATrue
- BFalse
66kills a specific process with signal 9 → SIGKILL
- A$ kill 12345
- B$ kill -9 12345
- C$ kill -9 -1
- D$ man -s 7 signal
67signal lifetime:
- Aa signal is generated/sent, usually as a consequence of some event
signal is delivered/pending to a process
delivered signal is handled by the process via signal handler
some signals can be ignored - signal delivered to a process that ignores it is lost
some signals can be blocked - signal stays pending until it is unblocked - Bsignal is delivered/pending to a process
a signal is generated/sent, usually as a consequence of some event
delivered signal is handled by the process via signal handler
some signals can be ignored - signal delivered to a process that ignores it is lost
some signals can be blocked - signal stays pending until it is unblocked
- Aa signal is generated/sent, usually as a consequence of some event
68reentrant functions are functions:
-that can be interrupted in the middle of an operation
-and then called again (re-entered)
-and finally the original function call can finish executing- ATrue
- BFalse
69There are 3 Process states: running, blocked, and ready
- ATrue
- BFalse
70A process can send a signal to another process and even itself.
- ATrue
- BFalse
71Kernels cannot send signals to processes
- ATrue
- BFalse
72$kill -9 (sends signal 9 to all processes and will shutdown the system if called by the root user)
- ATrue
- BFalse
73What does the volatile keyword do?
- Aallows for spontaneous change, disables compiler optimization
- Boverwrites the memory address randomly
- Cdoesn't save the data once the system is powered down
74It is okay to use a global variable in a reentrant function
- ATrue
- BFalse
75if you have a global variable used in function that is desired to be reentrant, move this variable inside of the function itself
- ATrue
- BFalse
76Process states
only 4 transitions are possible:
ready → running
running → ready
running → blocked
blocked → ready- ATrue
- BFalse
77IPC means Inter Process communication
- ATrue
- BFalse
78Threads and processes are separate
- ATrue
- BFalse
79Threads are subsets of processes
- ATrue
- BFalse
80Threads can share some things while processes cannot.
- ATrue
- BFalse
81Threads communicate through shared memory, which is the fastest form of communication
- ATrue
- BFalse
82Threads can make system calls simultaneously
- ATrue
- BFalse
83In general each thread has its own registers (including its own program counter), its own stack pointer, and its own stack. Everything else is shared between the threads sharing a process
- ATrue
- BFalse
84pthread_create(thread, attr, start_routine, arg)
starts a thread, similar to fork()- ATrue
- BFalse
85pthread_exit(status)
terminates the current thread, similar to exit(), or you can return from start_routine- ATrue
- BFalse
86pthread_join(thread, * status)
- Ablocks the calling thread until the specified thread terminates, similar to wait()
- Bterminates the current thread, similar to exit(), or you can return from start_routine
- Cinitializes / destroys thread attributes
87pthread_create(thread, attr, start_routine, arg)
- Astarts a thread, similar to fork()
- Bblocks the calling thread until the specified thread terminates, similar to wait()
- Cterminates the current thread, similar to exit(), or you can return from start_routine
88pthread_attr_init(attr) and pthread_attr_destroy(attr)
- Ainitializes / destroys thread attributes, these can be fine-tuned with pthread_attr_set*() functions
- Bblocks the calling thread until the specified thread terminates, similar to wait()
- Cstarts a thread, similar to fork()
89pthread_kill(thread_id, signal) is only delivered to the target thread
- ATrue
- BFalse
90In synchronous cancellation: one thread finds the result being searched for by multiple threads, it should then update a global flag called "volatile in cancel_flag" to let all other threads know to stop.
- ATrue
- BFalse
91In asynchronous cancellation: one thread finds the result being searched for by multiple threads, it should then manually call "pthread_kill(threadid, SIGUSR1)" to kill the target thread. (Synchronous cancellation is safer and better)
- ATrue
- BFalse
92In synchronous cancellation: one thread finds the result being searched for by multiple threads, it can then call pthread_cancel(). The target thread will be periodically checking to see if it should terminate.
- ATrue
- BFalse
93race condition is a behavior where the output is dependent on the sequence or timing of other uncontrollable events (eg. context switching, scheduling on multiple CPUs)
- ATrue
- BFalse
94Which are examples of Race Conditions?
- Amodifying shared memory
- Breading/writing to files
- Cmodifying filesystems
- Dreading/writing to databases
- Eexecuting a local function
- Fchecking for mutex
- Gspinlocking
95Multiple threads simultaneously accessing the same global (shared) variable is thread-safe.
- ATrue
- BFalse
96Race condition problems could give false positives. (intended output)
- ATrue
- BFalse
97Race conditions:
C/C++ to assembly :
int counter;
int incr1() {
int x = counter;
x = x + 1;
counter = x;
}
to
mov eax, DWORD PTR counter[rip]
mov DWORD PTR [rbp-4], eax
add DWORD PTR [rbp-4], 1
mov eax, DWORD PTR [rbp-4]
mov DWORD PTR counter[rip], eax- ATrue
- BFalse
98Critical Sections are areas that create race conditions and are not (without adding a sync mech) thread-safe
- ATrue
- BFalse
99To avoid Race Conditons:
- AIdentify Critical Sections
- BEnforce Mutual Exclusion
- Cuse IPC
- Dswitch to Kernel mode
100Requirements for good race-free solution are:
Mutual exclusion: No two processes/threads may be simultaneously inside their critical sections (CS).
Progress: No process/threads running outside its CS may block other processes/threads.
Bounded waiting: No process/thread should have to wait forever to enter its CS.
Speed: No assumptions may be made about the speed or the number of CPUs.- ATrue
- BFalse
101deadlock: assuming reasonable sync, no threads get to execute (or at least some). Everyone is waiting for some other member to release a lock.
- ATrue
- BFalse
102livelock: assume all sync, no threads will execute as intended. The states keep on changing with regard to one another, none progressing.
- ATrue
- BFalse
103random timeout mechanism: try to do an action, if you fail, take a random short nap
- ATrue
- BFalse
104resource hierarchy solution: establishing a partial order on resources
- ATrue
- BFalse
105Mutex: if two threads call lock() simultaneously, both will proceed, the rest will block
- ATrue
- BFalse
106Mutex implementation: pthread_mutex_lock(&mutex), use &mutex for address space!!!!
- ATrue
- BFalse
107Concurrency:
starvation - one process does not get to run at all
unfairness - not all processes get equal opportunity to progress- ATrue
- BFalse
108Producer-consumer uses a fixed-size buffer
- ATrue
- BFalse
109Which bash looks in the current directory, prints the file names and sizes (with 20 characters) of the 10 largest files?
- A$ find . -type f -printf "%-20s%p\n" | sort -nr | head -n 10
- B$ find ./ -type f -printf "%-s%p\n" | sort -nr | head -n 10
- C$ find . -type f -printf "%s%p\n" | sort -nr | head -n 10
- D$ ls ./ -type f -printf "%-20s%p\n" | head -n 10
110Condition Variables are a signalling mechanism for mutex, not actual variables or conditions
// critical section protected with mutex m
lock(m)
…
while( ! some_condition() ) {;}
…
unlock(m)- ATrue
- BFalse
111pthread_cond_t cond; // set a condition variable
- ATrue
- BFalse
112pthread_cond_wait(&cond, &mutex);
atomically releases mutex and causes the calling thread to block, until some other thread calls pthread_cond_signal(&cond)- ATrue
- BFalse
113pthread_cond_signal(&cond);
wakes up one thread waiting on cond
if no threads waiting on cond, the signal is lost
must be followed by pthread_mutex_unlock() if the blocked thread uses the same mutex- ATrue
- BFalse
114Convert count++; to assembly
- Areg1++
- Breg1 = count
reg1 = reg1 + 1
count = reg1 - Creg1 = count
reg1 = reg1 + count
count = reg1
115while loops within CS (Critical Section) should be checked for deadlock.
- ATrue
- BFalse
116If a signalling mech is in an "if statement" and not a "while loop", change it to a while loop.
- ATrue
- BFalse
117Semaphores will NOT block if they go below zero
- ATrue
- BFalse
118Atomic operations appear to execute instantaneously
- ATrue
- BFalse
119semaphores must be initialized with a value of 0 or greater.
semaphore s;
wait(s);
// Critical Section
signal(s);- ATrue
- BFalse
120unlike mutexes, semaphores can be unlocked by any thread. Mutexes must be unlocked by the same thread that locks it.
- ATrue
- BFalse
121sem_post() compared to cv_signal():
- cv_signal() is lost (has no effect) if no thread is waiting
- sem_post() increments the semaphore always, and possibly wakes up a thread- ATrue
- BFalse
122sem_wait() compared to cv_wait():
- cv_wait() always blocks
- sem_wait() checks the value of the semaphore, and may or may not block- ATrue
- BFalse
123monitors are NOT modules that encapsulate.
- ATrue
- BFalse
124Spinlocks are a lightweight alternative to mutex implemented using busy waiting loops. Usually implemented in assembly, using atomic operations. No rescheduling required.
- ATrue
- BFalse
125event flags: a memory word with N bits
- different events may be associated with different bits in a flag
operations:
set flag
clear flag
wait for 1 flag
wait for any flag
wait for all flags- ATrue
- BFalse
126A single, shared (lock) variable, initialized to 0.
lock == 0 : no process is in CS
lock == 1 : a process is in CS
But this has a mutual exclusion problem- ATrue
- BFalse
127Peterson's algorithm uses
- Ashared integer variable turn - indicating whose turn it is
shared array flag[2] - indicating who is interested in entering CS, initialized to 0 - Bshared integer variable mutex
spinlock algorithm - Cmap data-structure
CPU hyperthreading
- Ashared integer variable turn - indicating whose turn it is
128Peterson's algorithm for two processes
while(1) {
flag[0] = TRUE;
turn = 1;
while (flag[1] && turn == 1) {}
critical_section
flag[0] = FALSE;
non-critical-section
}- ATrue
- BFalse
129ready queue:
- Aall processes that are ready to execute their next instruction
eg. linked list, implemented via a pointers in PCBs - Bprocesses waiting for a particular device
each device has its own queue - Call programs waiting to run, usually found in batch systems
eg. priority queue
- Aall processes that are ready to execute their next instruction
Information
- Description
- Quiz on Untitled, created by Connor Britton on 27/10/2019.
- Author
- Connor Britton
- Language
- English
- Views
- 0
- Rating
- No ratings yet Rate this quiz