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