OS Flashcards

1
Q

What is an operating system?

A

The one program that always runs on a computer, that acts as an intermediary between a ‘user’ of a
computer and the computer hardware

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

What does an operating system do?

A
  • Allocates resources such as CPU time, memory and storage
  • Decides between conflicting requests
  • Controls execution of programs to prevent errors and improper use of the computer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the bootstrap and what does it do?

A

Program stored on the ROM or EPROM that is loaded after boot that initialises firmware and loads the operating system

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

What is a device controller?

A

Controller: Hardware that manages the data flow between the CPU and the device such as mice, keyboards etc. They include local buffers where data moves between that and memory.

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

What is stored in the interrupt vector? What is a trap?

A

IV: Address of instruction, Interrupt service routine
Trap: Interrupt called by software

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

What is a system call?

A

When a process accesses the kernel to call a function. Examples are create file, write console, set file security etc. Usually goes through API instead of direct interaction with kernel

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

How can software interrupt processing when its called from the user space and not the kernel space?

A

Index is stored in a well known location before moving to kernel space which looks up the interrupt via the index and executes it.

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

What is dynamic linking?

A

programs that use libraries all call to a single library stored somewhere

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

what is swapping

A

allocating virtual memory and moving processes across to virtual memory

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

What are the two types of fragmentation?

A
  • External fragmentation: Holes made due to processes of different sizes being allocated and reallocated
  • Internal fragmentation: When processes that are slightly larger than blocks they are allocated meaning that the last block will have unused space
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is paging?

A

Splitting memory into equally sized blocks and allocating memory by blocks to processes. This prevents external fragmentation. Page table is stored in registers or cache depending on size

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

What is segmentation?

A

Allocating space depending on process size. Data, program code and symbol table is stored within.

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

What is thrashing?

A

When data in virtual memory pages need to be accessed frequently causing processing time to decrease due to long read write times between disk and memory. can be prevented by defining working set as most frequently used pages and keeping them stored in memory and less used ones in virtual memory.

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

How does the kernel code execute separately to user code?

A

They have strictly different spaces in memory. Kernel either executes system calls from user processes sent by user or handles device interrupts.

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

What are the three linux commands related to running kernel modules?

A
  • modprobe inserts module into running kernel
  • rmmod removes module from running kernel (if unused)
  • lsmod lists currently running modules
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are critical sections in memory and how do they work?

A

Areas that enforce data structures only being accessed by one thread at a time. This can be done with mutex locks which put the thread to sleep until the structure is unlocked or spinlocks which get the thread to repeatedly check if the structure is unlocked until it is let in.

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

What are device drivers?

A

Software that runs in kernel mode that allows other processes to access and interact with devices through device controllers. They have opererations such as open, read, write and close on the device.

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

What happens when in a device driver interrupt?

A
  • device sends interrupt
  • CPU selects appropriate interrupt handler
  • Interrupt handler: performs read/write action on device, wakes up processes waiting on interrupt
  • Clears interrupt bit of device to allow next interrupt to come
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is inside a process?

A

Stack (for function calls and related data) and heap (dynamic memory allocation), data (static and global variables and constants) and the code. Stack and heap grow towards each other in the free space

19
Q

What are the states of a process?

A

New (being created), ready (to be assigned to a processor), running, waiting (for an event), terminated

19
Q

What information is associated and stored with a process?

A
  • Process state
  • Program counter
  • CPU registers
  • CPU scheduling information
  • Memory-management information
  • Accounting information
  • I/O status information
20
Q

How are processes created?

A

Processes create other processes forming a tree. Processor IDS (pids) are used to identify them. Parent and child processes may or may not share resources or children may use a subset of parent’s resources. Processes may be executed concurrently or parents wait until child processes terminate.

21
Q

What happens when processes are terminated?

A

Processes ask OS to delete (exit), Resources may be sent to parent processes or deleted. Or parent processes may (abort) child processes.

22
Q

What happens in a context switch (CPU swapping to interrupt process)?

A

Process state is saved in process control block (PCB) including program counter, register values and memory management details. New process context is loaded. CPU cannot be used while switching (costly).

23
Q

What type of scheduling does the OS do?

A
  • Job queue in CPU
  • Ready process queue in memory
  • Device queue for processes waiting on devices
24
Q

What factors do CPU scheduling algorithms try to maximise/ minimise?

A
  • CPU utilisation
  • Throughput (rate of processes executed)
  • Turnaround time (average execution time)
  • Wait time (in ready queue)
  • Response time (time taken since request to be executed)
25
Q

What are the two categories of process in the CPU?

A
  • I/O bound process: spends more time doing I/O. needs multiple short times in CPU (bursts).
  • CPU bound process: spends more time in computation. needs few long bursts in CPU.
26
Q

What type of scheduling algorithms are there?

A
  • FCFS
  • Round Robin (FCFS but if processes take too long get moved to the back: preemption)
  • Shortest Job First
  • Priority Queue. Can be with preemtion (new higher priority job can kick out current one)
  • Multilevel Queue Scheduling: Jobs split into groups with their own scheduling algorithm
27
Q

What is processor affinity?

A

When multiple CPUs are available, processes may prefer old CPU when scheduled (soft affinity) or can only be rescheduled on old CPU (hard affinity). This is so that cache is valid when rescheduled.

28
Q

What is load balancing?

A

Goes against affinity to ensure all CPUs are equally loaded.
* Push migration is when a busy CPU pushes jobs to other, less loaded CPUs
* Pull migration is when an idle CPU takes jobs from other CPUs

29
Q

How does linux implement a round robin scheduler with priorities?

A

Orders processes based on run time allocated so instead of getting sent to the back, gets sent to the place that corresponds to how much CPU time its had.

30
Q

What is a critical section of a process?

A

A section of the process that accesses shared resources that requires sole access otherwise errors could occur with multiple operations being done in different orders producing different results

31
Q

What is Peterson’s algorithm for the critical section problem?

A

Variable ‘turn’ is the lock and an array stores boolean values of if the processes want access or not. This prevents both processes going to take the lock at once.

Only works for two procces and if one processes swaps out of CPU, other waits unnecessarily. Assumes instructions are atomic

31
Q

What is a lock?

A

Something that a process obtains when working on shared resources that ensure that it is the only process working on the resource at that time.

32
Q

What is TestAndSet and how can it help us get a lock?

A

It is a single CPU instruction that sets a variable to true and returns the original value. It is atomic (cannot be interrupted), meaning if we use it on the lock, no errors can occur when two processes go to take it at the same time. If it returns False, the swap was successful, otherwise, it wasnt.

33
Q

What is the difference between a spinlock and using sleep()?

A

Spinlocks have a constantly running while loop that checks for the lock to be free before entering the critical section. sleep() can be used instead to just sleep if its not free and when a process drops the lock, it wakes all the waiting processes.

34
Q

Why do we need semaphores?

A

So that the check if lock is in use and sleep() instructions are executed without interruption between because otherwise, the process may get swapped out of the CPU and when the call to wake up happens, it won’t do anything

35
Q

What is a semaphore?

A

An object with:
* A counter that represents how many more processes can run in the critical reigon on the resource that its protecting
* A wait() function that decrements the counter by one, allowing the process to proceed or if its 0, blocks access
* A signal function that increments the counter by one and wakes up the next process

36
Q

What is deadlock?

A

When two processes are waiting for each other, resulting in them waiting forever

37
Q

How do read/write locks work with binary semaphores (mutex locks)?

A
  • Multiple readers can access the resource at once on the condition that no writers are there
  • One writer can access the resource at once.
38
Q

What is a file allocation table (FAT)?

A

A table that keeps track of which clusters of secondary storage are used by a file. For example, if a file uses clusters 2,3,7,4, it will be directed to 2 in the FAT which points to 3 which points to 7 etc.
FAT can be cached to improve effciency however improper shutdown leads to inconsistency

39
Q

What three movements does the disk need to do with every operation?

A
  • Seek: move head to correct track
  • Latency: wait for correct block to be under head
  • Transfer: do operation
40
Q

What are some disk scheduling algorithms?

A

FCFS, Shortest job, scan scheduling (goes back and forth from end to end completing every job in its path in order of visitation), look scheduling (same as scan scheduling but only keeps moving if there is another request waiting)

41
Q

What happens with device drivers during boot?

A

Checks for devices and gets their device type, unique id and vendor. Sends to user space and then loads appropriate module

42
Q

What are the instructions for threads?

A
  • pthread_mutex_init(&mutex, NULL);
  • pthread_mutex_lock/unlock(&mutex);
  • pthread_mutex_destroy(&mutex);
43
Q

What are the instructions for a mutex?

A
  • pthread_t thread;
  • pthread_create(&thread, NULL, thread_function, NULL);
  • pthread_join(thread, NULL);
44
Q

how do you create a string?

A

char string[size]
or
char * string
string = malloc(size)