CPSC/ECE 3220

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/151

flashcard set

Earn XP

Description and Tags

Operating Systems Final

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

152 Terms

1
New cards

Operating System definition

System software that manages a computer’s hardware and software resources which acts as an intermediary between the user and computer’s hardware.

2
New cards

Operating System Roles

Referee, Illusionist, Glue

3
New cards

OS - Referee

The OS manages resources shared between different applications running on the same machine

4
New cards

OS - Illusionist

The OS gives the illusion that a process has isolated access to all the computer’s resources.

5
New cards

OS - Glue

The OS provides a set of common services that facilitate sharing among applications.

6
New cards

Kernel Defintion

The kernel is the lowest level of software running on the system which has access to all hardware.

7
New cards

Microkernel

An OS that is designed to run as much of the OS as possible in user-level servers.

8
New cards

Benefits of Microkernels:

  • Security

  • Modularity

  • Portability

  • Less kernel error

9
New cards

Cons of Microkernels

  • Slow (due to IPC)

10
New cards

What is REQUIRED to be in the kernel?

  • Memory management

  • Process scheduling

  • Interrupt handling

  • Direct hardware access

11
New cards

What is a trap (user → kernel)?

A synchronous, software initiated exception that causes a mode switch

12
New cards

What are some triggers of traps?

  • System calls

  • Software exceptions

13
New cards

Mode switch definition

A change between user → kernel (or vice versa). This can occur due to system calls, interrupts, or exceptions/traps.

14
New cards

What happens during a trap?

  1. CPU switches privilege level (mode switch) from user → kernel

  2. Saves user-mode state (registers, PC) to kernel stack

  3. Switches to kernel stack

  4. Jumps to appropriate kernel handler

  5. Kernel executes required operation

  6. Returns to user mode (mode switch) which restores registers and switches back to user stack

15
New cards

What is a context switch (kernel → user)?

A context switch is when the CPU switches from one process to another.

16
New cards

What happens during a context switch?

  1. Timer interrupt or system call triggers kernel mode

  2. Kernel saves Process A’s entire context (PCB)

  3. Scheduler selects process B

  4. Kernel restores process B’s context from its PCB

  5. Switch page tables (change virtual memory mapping)

  6. Return to user mode in Process B

17
New cards

What are system calls?

Synchronous requests for kernel services or access to system resources (managed by kernel)

18
New cards

What are interrupts?

Asynchronous signals to the processor that some event has occurred that may require attention (I/O completion, error)

19
New cards

What are library calls?

User-space functions that run entirely in user mode (no kernel involvement, fast)

20
New cards

What is a signal?

Software notifications/interrupts sent to a process to notify it of an event (integer)

21
New cards

SIGINT

Ctrl + C

22
New cards

SIGKILL

Force kill (can’t be caught or ignored)

23
New cards

SIGTERM

Polite termination request (can be caught)

24
New cards

SIGSTOP

Pause the process (can’t be caught)

25
New cards

What is the role of interrupts in modern operating systems?

Interrupts allow the OS to regain control of the processor. Allows for preemptive scheduling and responds to hardware events asynchronously

26
New cards

Timer interrupts

Will interrupt the processor after a specified time period (force mode switch to kernel)

27
New cards

Device Interrupts

Notify when I/O completes

28
New cards

What does a process look like to the programmer?

To the programmer, a process has a code body, global variables, heap memory, and stack memory.

29
New cards

What does a process look like to the operating system?

To the OS, a process is portrayed as a PCB which contains registers, memory information, address space, and process ID.

30
New cards

What is a thread?

A lightweight execution unit within a process

31
New cards

A process differs from a thread in which ways?

  • Separate address space

  • Independent resources

  • Isolated

32
New cards

A thread differs from a process in which ways?

  • Shared address space

  • Shared resources

  • Own stack and registers

33
New cards

What is a PCB?

The PCB is what contains information about a process’s state. It is what is tracked by the OS.

34
New cards

What is a TCB?

The TCB contains registers and anything needed to resume the thread.

35
New cards

What is held within the PCB?

  • Process ID

  • Process state

  • PC

  • I/O status

  • Memory information

  • Address space

  • Processor Registers

36
New cards

What is held within the TCB?

  • The stack pointer to the thread’s stack

  • Copy of processor registers

  • PC

  • Thread ID

  • Thread state

  • Pointer to thread’s PCB

  • Scheduling information

37
New cards

pthread_create()

int pthread_create(thread ID, thread Attributes, Function to run, Argument to pass)

38
New cards

pthread_join()

  • Waits for target thread to finish

  • int pthread_join() thread ID, void **return value)

39
New cards

What are kernel threads?

Threads that are created and scheduled by the kernel (pthread_create)

40
New cards

What are user threads?

Threads that the kernel is not aware of (virtual threads)

  • Requires at least 1 kernel thread to have user-threads

  • CANNOT achieve parallel processing since all user-threads are on the same core

  • Switching from one thread to another is more efficient using user-threads since switching threads does not need to go through the kernel

41
New cards

What is a shim?

An intermediary layer that intercepts function calls between a program and a library

42
New cards

What do shims allow us to do?

Allows us to modify, monitor, or replace the behavior of function calls without changing the original process code.

43
New cards

What does LD_PRELOAD do?

LD_PRELOAD allows us to load our libraries prior to code execution.

44
New cards

Signals IPC and Pros & Cons

Sends the process an integer

  • Fast

  • Can be asynchronous

45
New cards

Shared memory IPC and Pros & Cons

Allows many processes to access a common memory region

  • Fastest

  • Concurrent access can cause data corruption

  • Memory region persists until explicitly removed or system reboot

46
New cards

Pipes IPC and Pros & Cons

A communication channel that connects a related process’s output to another process’s input

  • Allows for chaining

  • 1 direction for communication

  • Easy IPC

  • Fast

47
New cards

Named Pipes IPC and Pros & Cons

Allows unrelated processes to communicate by sending and receiving data through a special file in the filesystem

  • Opening a named pipe blocks until both a reader and writer are present

  • Rely on conventions (white space or newline) for termination

48
New cards

Messages IPC and Pros & Cons

Uses a key-based queue system to allow communication

  • The client can send a message and terminate with the server being able to retrieve the message later

  • Clear sender/receiver roles

  • Each process works with its own queue

  • Can cause collisions if another program uses the same keys

49
New cards

Sockets IPC and Pros & Cons

A server sets up a network (localhost), which is used to communicate with clients

  • slow

  • flexible

  • can be asynchronous

50
New cards

What is a TCP socket?

A socket that is only connected by the client and the server which can see the message.

51
New cards

What is a UPD socket?

A socket that allows many processes to receive the same message.

52
New cards

What are the exec variations and what do they do? (4 of them)

  • l = list (arguments as separate parameters)

  • v = vector (arguments as an array)

  • p = PATH (search PATH for executable)

  • e = environment (specify custom environment variables)

53
New cards

What is the ptrace structure?

long ptrace(int request, pid_t pid, void *addr, void *data)

54
New cards

What does ptrace allow us to do?

Allows us to observe and control another process

55
New cards

What are race conditions?

Race conditions occur when multiple threads access shared data concurrently and the final result depends on the timing/ordering of their execution.

56
New cards

How do we prevent race conditions?

  • Mutex locks

  • Semaphores

  • Condition Variables

  • Atomic Operation

  • Spin locks

57
New cards

What are spinlocks?

Mutex locks that continuously check if the lock is free

  • Good for short wait times

58
New cards

What are mutex locks?

Makes an operation atomic and sleeps an operation if the lock is not available

  • Good for single core

59
New cards

What is a binary semaphore?

A semaphore whose value can only be 1 or 0

  • 1 = available/unlocked

  • 0 = unavailable/locked

60
New cards

What are counting semaphores?

A counting semaphore allows up to N threads to run at the same time

  • N = amount of threads (initial val)

  • 0 = block threads

61
New cards

What are condition variables?

Condition variables have a thread waiting queue for threads to wait when the work queue is empty.

  • Producer/consumer relationship

62
New cards

What are Read and Write locks?

Locks that allow for many reader threads but only one writer at a given time.

63
New cards

What is a deadlock?

Waiting on a resource that will never become available

Requires:

  • Mutual exclusion

  • Hold and wait

  • No preemption

  • Circular wait

64
New cards

What does parallel mean?

Working on different processes at the same time

65
New cards

What does concurrency mean?

Working at several tasks at once (does not mean at the same time)

66
New cards

What is global scope/ system scope?

Scheduling that treats all threads as equal and does not look at which process they are from.

67
New cards

What is local scope/ process scope?

Scheduling that chooses a process and then threads within that process compete against each other.

68
New cards

What is CPU affinity?

Allows us to choose which core a thread runs on, and that thread cannot run on other cores.

69
New cards

Why do we use CPU affinity?

It is used for cache performance since we do not need to transfer cache since the thread stays on the same core.

70
New cards

pthreads condition variable implementation

// pthread condition variable
pthread_mutex_lock(&mutex);
pthread_cond_wait(&cond, &mutex);  
// When this returns, you HAVE the lock again!
pthread_mutex_unlock(&mutex);

71
New cards

pthreads mutex locks implementation

// pthread mutex lock
pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_lock(&m);
pthread_mutex_unlock(&m);
pthread_mutex_trylock(&m);  // Returns 0 if successful

72
New cards

FSFC (FIFO) Scheduling

First come first serve

73
New cards

Round Robin Scheduling

Each process gets a designated amount of time with the CPU

74
New cards

SJF scheduling

The shortest job is scheduled first

75
New cards

Fair Share scheduling

Allocates CPU time based on the user/group that owns the process. Each user/group is designated the same amount of CPU time regardless of amount of processes.

76
New cards

EDF Scheduling

The process/thread with the earliest deadline first is scheduled

77
New cards

Least Slack scheduling

The process/thread with the least amount of time before its deadline (deadline - current progress) is scheduled first.

78
New cards

Rate monotonic scheduling

Processes/threads that occur the most often at a set rate are scheduled first.

79
New cards

What is priority?

A process/thread with the most priority is favored to be run first.

80
New cards

What is multilevel priority queueing?

Where there are several queues that represent priority levels.W

81
New cards

What is multilevel feedback queueing (MFQ)?

Multilevel priority queueing but processes can change priority queues based on their behavior.

82
New cards

What is an admission-control algorithm/system?

A system that decides whether to accept or reject a new process/thread based on whether the system has sufficient resources to handle it.

83
New cards

Why would we need an admission-control system?

To prevent system overload or thrashing

84
New cards

Short-term scheduler

Decides what process to run next

85
New cards

Medium-term scheduler

Decides how many process to run

86
New cards

Long-term scheduler

Decides whether to accept/reject a new process

87
New cards

Copy-On-Write

Multiple processes use the same frame, but will copy the data to another frame if a process has written to it.

88
New cards

Hugepages

OS have started to have designated memory blocks for processes that are much larger than the page size.

89
New cards

Explicit Memory Management

The programmer must free no-longer-needed memory.

90
New cards

Implicit Memory Management

The programmer does not need to free memory manually.

91
New cards

Garbage Collectors

Automatic memory management features that typically use reference counters to determine to free memory.

  • If a reference counter hits 0, then we can free it

92
New cards

Why does C not have garbage collectors?

In C, we cast types to pointers and garbage collectors will view any 8-byte memory block as a pointer since there is no way for certain to determine that “this block is a pointer”.

93
New cards

Segment Table

A table that has an entry for each segment of memory and stores the base address for the segment and its size.

94
New cards

Segmentation Details

  • Slow because of the comparison and addition instructions on every memory access

  • External fragmentation

95
New cards

External Fragmentation

Little pieces of memory that are never used (too small to accommodate most processes).

96
New cards

Defragmentation

Copying memory and moving it up in the HHD/RAM/etc.

  • If we do not care about security, we can leave old data in the old address spaces

  • Costly

  • Slow

97
New cards

Pages

Virtual memory chunks

98
New cards

Frames

Physical memory chunks

99
New cards

All memory chunks are the ____ size in both virtual and physical memory?

  1. Same

  2. Different

100
New cards

Internal Fragmentation

Wasted memory space within memory chunks.