User Mode, Kernel Mode, Interrupts and System Calls Flashcards

1
Q

What architecture do modern computers use? Where are the programs and data stored?

A

Von Newman. Stored in ram.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How is data transferred from CPU, to RAM, ROM and devices?

A

Through the address and data bus.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What can a service do in Kernel mode?

A

Can run any instruction, modify any location in memory, can access any register.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What mode to OS services run in? Kernel or User?

A

Kernel, they need full control.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What can a service do in User mode?

A

CPU can use limited instructions, limited sections of memory, limited registers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What happens with the modes when the OS boots?

A

It boots in Kernel mode to set up interrupt vectors and more. After starting the first process it moves to User mode.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When to programs switch from User to Kernel mode?

A

When an interrupt arrives.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Is more CPU time spent in User or kernel mode?

A

User

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why are user and kernel mode separated?

A

Security, Robustness (crash in user doesn’t kill os), and Fairness

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

If a bug occurs in Kernel mode can the os crash?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What happens during an interrupt?

A

Hardware sets interrupt line to high, CPU jumps to interrupt handler, then returns to previous spot.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are some examples of interrupts?

A

move mouse
type key
ethernet packet

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the specific steps of serving an interrupt?

A
          1. The CPU saves the Program Counter and
            registers in execution stack
            CPU looks up the corresponding interrupt
            handler in the interrupt vector.
            CPU jumps to interrupt handler and run it.
            CPU restores the registers and return back to the
            place in the program that was interrupted. The
            program continues execution as if nothing
            happened.
            In some cases it retries the instruction the
            instruction that was interrupted (E.g. Virtual
            memory page fault handlers).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is polling in the context of handling tasks?

A

when the OS waits in a busy loop instead of using interupts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is Synchronous vs Asynchronous processing?

A

Polling is synchronous. Interrupt is asynchronous.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the interrupt vector?

A

It is an array of pointers that point to the different interrupt handlers of the different
types of interrupts.

17
Q

What are a couple of interrupt handlers?

A

Hard Drive Interrupt handler
USB Interrupt handler (mouse, kbd)
Ethernet Card Interrupt handler
Page Fault Interrupt handler

18
Q

Why must interrupts be handled in Kernel mode?

A

Instructions needed only available in Kernel mode.

19
Q

What are the different types of interrupts?

A

Device Interrupts, Math exceptions, Page Faults, Software Interrupt

20
Q

What is a system call?

A

How programs request services from the OS.

21
Q

What are some examples of system calls?

A

◼ open(filename, mode)
◼ read(file, buffer, size)
◼ write(file, buffer, size)
◼ fork()
◼ execve(cmd, args);

22
Q

Why are software interrupts needed for system calls?

A

Need Kernel mode for OS services

23
Q

Do all parts of the system call run in Kernel mode?

A

No, ex: for malloc most of it runs in user mode until sbrk() is called to extend the heap.

24
Q

What library provides wrappers for system calls?

25
What is checked in the sys call open(filename, mode) and by what?
The interrupt handler checks to make sure file exists, it also checks the permissions of the file being opened.
26
Where can a list of system calls be found?
/usr/include/sys/syscall.h
27
What happens when an error occurs in a system call?
OS sets global variable erno to number that gives reason for the error.
28
What does perror(s) do?
Prints erno and preapends s.
29
Explain each step of the call write(fd, buff, n)
he user program calls the write(fd, buff, n) system call to write to disk. The write wrapper in libc generates a software interrupt for the system call. The OS in the interrupt handler checks the arguments. It verifies that fd is a file descriptor for a file opened in write mode. And also that [buff, buff+n-1] is a valid memory range. If any of the checks fail write return -1 and sets errno to the error value. System Calls and Interrupts Example 4. The OS tells the hard drive to write the buffer in [buff, buff+n] to disk to the file specified by fd. 5. The OS puts the current process in wait state until the disk operation is complete. Meanwhile, the OS switches to another process. 6. The Disk completes the write operation and generates an interrupt. 7. The interrupt handler puts the process calling write into ready state so this process will be scheduled by the OS in the next chance.
30
What is the Strace command?
It is a tool that prints the system calls that a program calls ex: strace ./hello