Quiz
Kernel and user mode: CPU cycles, boot and interrupts
Erstelle ein kostenloses Konto, um dieses Quiz zu beenden
Speichere deinen Fortschritt und sieh dir dein Endergebnis an.
oder mit deiner E-Mail registrieren
Schon ein Konto? Anmelden
Fragen in diesem Quiz (129)
1A single CPU cycle has 3 units: Fetch, Decode, and Execute
- ARichtig
- BFalsch
2A single CPU cycle has 2 units: Fetch and Execute
- ARichtig
- BFalsch
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
- ARichtig
- BFalsch
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.
- ARichtig
- BFalsch
7On boot, Kernel is the first thing started
- ARichtig
- BFalsch
8BIOS is the first stage of boot
- ARichtig
- BFalsch
9Kernel gets loaded and started by the bootloader
- ARichtig
- BFalsch
10User mode does not have all instructions available
- ARichtig
- BFalsch
11Only kernel and some drivers can run in kernel mode
- ARichtig
- BFalsch
12User mode can see the state of the CPU
- ARichtig
- BFalsch
13Some applications can run in kernel mode, with restrictions
- ARichtig
- BFalsch
14Which are in user mode?
- Acompilers
- Bkernel
- Csystem calls
- Dinterrupts
- EGUIs
- Fassemblers
15Running in root is still running in User mode.
- ARichtig
- BFalsch
16The OS and the kernel are separate.
- ARichtig
- BFalsch
17Illegal instructions in User mode result in traps (interrupts). They are then handled in Kernel mode.
- ARichtig
- BFalsch
18user mode invokes a special type of interrupt called a trap, to switch from user mode to kernel mode.
- ARichtig
- BFalsch
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)
- ARichtig
- BFalsch
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.
- ARichtig
- BFalsch
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
- ARichtig
- BFalsch
26Software interrupts are an only from the CPU (anything else sending an interrupt is considered a hardware interrupt)
- ARichtig
- BFalsch
27Interrupts cannot interrupt other interrupts
- ARichtig
- BFalsch
28Types of kernels
- Amonolithic kernel
- Bmicrokernel
- Chybrid kernel
- Dmacrokernel
- Etrilithic kernel
- Fdual kernel
29Larger kernels have more bugs and therefore have more instability
- ARichtig
- BFalsch
30code runs faster not in kernel
- ARichtig
- BFalsch
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
- ARichtig
- BFalsch
33Any popular service on the internet actually runs on a virtual machine.
- ARichtig
- BFalsch
34VMs are aware that they are virtual and not physical machines
- ARichtig
- BFalsch
35VM cannoy talk to each other
- ARichtig
- BFalsch
36A hypervisor runs the VMs on either bare-metal, hosted, or hybrid.
- ARichtig
- BFalsch
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
- ARichtig
- BFalsch
39System calls are implemented as library calls
- ARichtig
- BFalsch
40I/O are not system calls
- ARichtig
- BFalsch
41a kernel can be thought of as a really big library for system calls.
- ARichtig
- BFalsch
42system calls are implemented in assembly and higher level wrappers utilize them
- ARichtig
- BFalsch
43Wrappers reduce portability between systems
- ARichtig
- BFalsch
44Making system calls is expensive, but making library calls is cheap
- ARichtig
- BFalsch
45"write()" is wrapper for system call 4
- ARichtig
- BFalsch
46Which of these system calls send a signal?
- Akill()
- Bsignal
47signal() system call is used to send signals
- ARichtig
- BFalsch
48fork() is used to duplicate a process on linux
- ARichtig
- BFalsch
49bash: strace is used to see every system call that was used
- ARichtig
- BFalsch
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- ARichtig
- BFalsch
51A pipe takes the output of the first one and makes it the input of the second one
- ARichtig
- BFalsch
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
- ARichtig
- BFalsch
54Each process gets its own address space in memory
- ARichtig
- BFalsch
55PCB is a Process Control Block, in this course
- ARichtig
- BFalsch
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
- ARichtig
- BFalsch
58printf() is buffered on most linuxes and should never have outputs "overlap"
- ARichtig
- BFalsch
59forks spawn 2^n processes, where "n" is the number of fork calls.
- ARichtig
- BFalsch
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
- ARichtig
- BFalsch
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
- ARichtig
- BFalsch
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- ARichtig
- BFalsch
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- ARichtig
- BFalsch
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- ARichtig
- BFalsch
69There are 3 Process states: running, blocked, and ready
- ARichtig
- BFalsch
70A process can send a signal to another process and even itself.
- ARichtig
- BFalsch
71Kernels cannot send signals to processes
- ARichtig
- BFalsch
72$kill -9 (sends signal 9 to all processes and will shutdown the system if called by the root user)
- ARichtig
- BFalsch
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
- ARichtig
- BFalsch
75if you have a global variable used in function that is desired to be reentrant, move this variable inside of the function itself
- ARichtig
- BFalsch
76Process states
only 4 transitions are possible:
ready → running
running → ready
running → blocked
blocked → ready- ARichtig
- BFalsch
77IPC means Inter Process communication
- ARichtig
- BFalsch
78Threads and processes are separate
- ARichtig
- BFalsch
79Threads are subsets of processes
- ARichtig
- BFalsch
80Threads can share some things while processes cannot.
- ARichtig
- BFalsch
81Threads communicate through shared memory, which is the fastest form of communication
- ARichtig
- BFalsch
82Threads can make system calls simultaneously
- ARichtig
- BFalsch
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
- ARichtig
- BFalsch
84pthread_create(thread, attr, start_routine, arg)
starts a thread, similar to fork()- ARichtig
- BFalsch
85pthread_exit(status)
terminates the current thread, similar to exit(), or you can return from start_routine- ARichtig
- BFalsch
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
- ARichtig
- BFalsch
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.
- ARichtig
- BFalsch
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)
- ARichtig
- BFalsch
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.
- ARichtig
- BFalsch
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)
- ARichtig
- BFalsch
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.
- ARichtig
- BFalsch
96Race condition problems could give false positives. (intended output)
- ARichtig
- BFalsch
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- ARichtig
- BFalsch
98Critical Sections are areas that create race conditions and are not (without adding a sync mech) thread-safe
- ARichtig
- BFalsch
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.- ARichtig
- BFalsch
101deadlock: assuming reasonable sync, no threads get to execute (or at least some). Everyone is waiting for some other member to release a lock.
- ARichtig
- BFalsch
102livelock: assume all sync, no threads will execute as intended. The states keep on changing with regard to one another, none progressing.
- ARichtig
- BFalsch
103random timeout mechanism: try to do an action, if you fail, take a random short nap
- ARichtig
- BFalsch
104resource hierarchy solution: establishing a partial order on resources
- ARichtig
- BFalsch
105Mutex: if two threads call lock() simultaneously, both will proceed, the rest will block
- ARichtig
- BFalsch
106Mutex implementation: pthread_mutex_lock(&mutex), use &mutex for address space!!!!
- ARichtig
- BFalsch
107Concurrency:
starvation - one process does not get to run at all
unfairness - not all processes get equal opportunity to progress- ARichtig
- BFalsch
108Producer-consumer uses a fixed-size buffer
- ARichtig
- BFalsch
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)- ARichtig
- BFalsch
111pthread_cond_t cond; // set a condition variable
- ARichtig
- BFalsch
112pthread_cond_wait(&cond, &mutex);
atomically releases mutex and causes the calling thread to block, until some other thread calls pthread_cond_signal(&cond)- ARichtig
- BFalsch
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- ARichtig
- BFalsch
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.
- ARichtig
- BFalsch
116If a signalling mech is in an "if statement" and not a "while loop", change it to a while loop.
- ARichtig
- BFalsch
117Semaphores will NOT block if they go below zero
- ARichtig
- BFalsch
118Atomic operations appear to execute instantaneously
- ARichtig
- BFalsch
119semaphores must be initialized with a value of 0 or greater.
semaphore s;
wait(s);
// Critical Section
signal(s);- ARichtig
- BFalsch
120unlike mutexes, semaphores can be unlocked by any thread. Mutexes must be unlocked by the same thread that locks it.
- ARichtig
- BFalsch
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- ARichtig
- BFalsch
122sem_wait() compared to cv_wait():
- cv_wait() always blocks
- sem_wait() checks the value of the semaphore, and may or may not block- ARichtig
- BFalsch
123monitors are NOT modules that encapsulate.
- ARichtig
- BFalsch
124Spinlocks are a lightweight alternative to mutex implemented using busy waiting loops. Usually implemented in assembly, using atomic operations. No rescheduling required.
- ARichtig
- BFalsch
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- ARichtig
- BFalsch
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- ARichtig
- BFalsch
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
}- ARichtig
- BFalsch
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
Informationen
- Beschreibung
- Quiz am Ohne Titel, erstellt von Connor Britton am 27/10/2019.
- Autor
- Connor Britton
- Sprache
- English
- Aufrufe
- 0
- Bewertung
- Noch keine Bewertungen Bewerte dieses Quiz