OS & System Programming Flashcards

Revise This Module for Exams

1
Q

What is Von Neumann Architecture also known as?

A

Stored-program computer

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

What is a Stored-program computer

A

A computer that stores program instructions in memory

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

Does Reprogramming require any change in hardware?

A

NO

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

What are the Architecture 3 main components?

A
  • CPU
  • Memory
  • I/0 Interface
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the CPU?

A

Heart of the Computing System

Includes:
- Control Unit (CU)
- Arithmetic Logic Unit (ALU)

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

What is Memory?

A

The computer’s memory stores program data & instructions

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

What I/O Interfaces?

A

They are used to receive or send information from the connection.

  • Connected devices are called peripheral devices.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How are programs executed on Von Neumann Computers?

A
  • Program is stored in memory
  • Translated in Machine code

1) CU understands that data needs to be provided by the user.

2) Data is Read from input device & bought to the CPU

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

What is ALU?

A

Union of the circuits for performing Arithmetic & Logical Operations

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

What is CU role?

A

Responsible for step-by-step execution of instructions during a program execution.

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

What are Registers?

A
  • Small storage element, located close to ALU
  • Used as temporary storage during computation
  • ALU can read & write from Registers very fast
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the advantages of using Registers?

A
  • Fast, does computation in Registers without constantly storing new values
  • Improves processing speed
  • Allows us to read data from memory once(Registers Store Immediate Data)
  • Reading Registers tend to have zero-time overhead
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Does CPU need Registers?

A

No, can use memory to store all the data

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

How long does it take to read/write data?

A

4ms

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

How long does Arithmetic take?

A

1ms

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

How is Memory Organised?

A
  • Memory consists of small ‘cells’
  • Each cell stores a small piece of data
  • cells have addresses 0 to n-1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Memory Access?

A
  • Read & Stores operations, CPU generates addresses
  • Memory Management unit reads or writes from/to memory location
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Decimal Representation :

A
  • Base 10 system
  • 0-9 are digits
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Binary Representation:

A
  • Base 2 System
  • digits are 0&1
  • digits called ‘bits’
  • 8 ‘bits’ are called a ‘byte’

eg: 1110 = 14

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

Hexadecimal Representation:

A
  • Base 16 System
  • Digits: 0,12,3,4,5,6,7,8, A,B, C,D, E, F

e.g : A3B = 2114

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

What is the General Structure of a C Program?

A
  • Execution begins at main()
  • Header of file contains imports / pre-defined libraries
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Examples of Control Flows?

A
  • if statements: conditional computation
  • if-else : Multiple Branching
  • Switch Statements
  • For / while/ do-while loops
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Basic if statement implementation?

A

if (condition) {
statement;
}

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

Example of if-else

A

if (condition) {
statement;
}
else if (condition) {
statement
}
else{
statement
}

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

Example of Switch

A

switch (condition){
case (A):
statement
break;
case (B):
statement
break;
default:
statement
break;
}

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

Example of for loop

A

for (int i; i < MAXRANGE; i++){
statement
}

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

Example of Conditional While Loop

A

while(condition){
statement
// Change condition or Not
}

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

Example of Infinite While Loop

A

while(1){
statement
// Can break the code
}

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

Example of Do While Loop

A

do {
statement
}
while (condition){
statement
}

// RUN THE CODE ONCE AND THEN DOES IT AGAIN IN WHILE LOOP

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

What does ‘continue;’ do?

A
  • skips the current iteration
  • Jumps to the beginning of the next iteration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

What does ‘break;’ do?

A
  • Comes out of the loop and the loop gets terminated.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Arrays in C?

A

int a[4] ; // Uninsialised

int b[3] = {2,3,4}

  • Fixed-size
  • Sequential collection of elements of the same type
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

What are errors with Arrays in C?

A
  • Compiler does not check array limit
  • Memory Protection was violated and the program crashed due to segmentation fault
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

How are Undefined Behaviours created?

A
  • Out-of-bound access
  • Signed int overflow
  • Div by Zero
  • UB hit, the program can theoretically do anything
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

Example of Function?

A

return_type func_name (arguments ) {
local variables declared
statements
return data of type declared
}

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

Format of printf() function:

A

printf(“%format”,variable_name);

format:
The Type for Variable name

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

What does printf() do?

A
  • Prints values into the standard ouptut
  • Defined in stdio.h library
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

What does scanf() do?

A
  • Receive inputs from keyboards
  • Defined in stdio.h library
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

Format of scanf() function:

A

scanf(“%format”,&variableName);

  • format is placeholder for Data type
  • &variableName is a pointer to store input into memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

What is a String?

A

-String of chars is a 1D array of chars
-Terminated by ‘\0’ == Null Char
- Can be read by scanf

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

What is strcpy()?

A
  • Copies a string to another memory location / a list of chars

strcpy(newCharLoc, aString);

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

What is strcat()?

A
  • concatenates 2 strings

strcat(string1, string2);

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

What is strlen()?

A
  • Gets the length of the string
  • strlen(string1);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

What is strcmp()?

A

-Compares 2 Strings

  • strcmp(str1,str2);
    – str1 == str2 = 0
    – str1 /= str2 = 1/-1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

What is a String Problem?

A
  • Ensure that sufficient memory is allocated at runtime (Not done in the compiler)
  • No checks at run-time, hence common source of errors
  • ‘Buffer Overflow’ has been exploited to achieve execution code supplied by the attacker
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

Solutions to String Problems?

A
  • The partial solution is to use the ‘safe’ function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q

What is the difference between C and Java?

A

Java:
- Memory allocated by compiler & length of string checked at runtime

  • Buffer overflows are impossible
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

Example of Safe String Functions?

A
  • Checks length so buffer doesn’t overflow
  • strncmp:
    • strncmp(str1,str2, sizeOf(str1));
  • strncpy:
    • strncpy(str1,str2, sizeOf(str1));
  • strncat:
    • strncat(str1,str2, sizeOf(str1))
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q

Pitfalls of Strings?

A

The string is length 10, will need a list of size 11 for the null char

If string is length 11 but the new list of char has space 8 because it does not have enough space for remaining char.

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

What is a Pointer?

A
  • A variable that contains the address of a variable
  • They can be passed into a function as an argument
  • Only do pass-by-ref
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

What is & / ‘Address of’?

A

p = &c
- Assigns Address of c to p

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

What is * “INDRIECTION / DEREFERENCING”?

A

c = *p
- *p hold the data c has

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

How to declare the pointer?

A

Type *p; // Declares pointer
int c = 5 , d , e[3];
int *p;

p = c; // p points to c
d = *p; // d has value 5
p = &e[0] // p points to e[0]

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

What is scale factor?

A

No. of Bytes used by the Data type

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

What does p++ or p+1 do is p is a pointer?

A

Points to the next object of the same type:

increments by:
- 4 when p is a float/int pointer
- 1 when p is a char pointer

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

What is the array name equal to?

A

It is an Address

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

What is Array Name synonymous with?

A

Location of the Initial Element

int *p = &a[0] <==> int *p = a

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

Can A pointer with direct Initalization be changed?

A

No, causes Segmentation fault & program crashes

example:
char *ptr = “Comp Sci”

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

Format for printing pointers?

A

print(“%p”p1);

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

Format for Returning Pointers?

A

type int *fun() {
Statement;
}

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

Define scope?

A

Part of program where variables can be used

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

What is held in Text or Code Segement?

A

Contains executable instructions/Programs

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

What does the Data Segments Contain?

A
  • Initalized and Unintialized Global & Static Variables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
64
Q

What are static variables?

A
  • Stores in data segment NOT STACK
  • Preserve their values even after they are out of their scope
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
65
Q

What are Global Variables?

A
  • Declared outside all functions
  • Can be read & Modified by all functions
  • Don’t name Local Vars the same as Global Vars
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
66
Q

What Does Stack Segment Store?

A

All Local or Automatic Variable , Arguments of Functions are also stored in stack.

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

What does Stack Segment do?

A
  • Gives each function call, its own stack frame
  • Stack grows from High to Low Address
  • After function returns values, the stack frame is released and all the local variables die
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
68
Q

What are Local Variables?

A

Scope is within function & allocated in the stack frame of the function

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

What does the Heap Segment store?

A

The storage of the dynamic memory allocation

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

What does .malloc() do?

A
  • Allocates requested number of bytes of contiguious memory from the heap
  • Returns a pointer of the first byte of allocated space
  • Memory Allocation fails, will return NULL POINTER
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
71
Q

What happens if dynamically allocated memory is not freed?

A
  • Memory will Leak
  • Memory not returned to Heap, then the program grow larger
  • Large programs cause slowdowns in system performance by reducing amount of avaliable memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
72
Q

What can I use to check for Memory Leaks?

A

Use Valgrind

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

What happens if you access memory after freeing it?

A

-Memory is not owned by the program

  • Re-accessing the freed memory can cause UNDEFIEND BEHAVIOUR (UB)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
74
Q

DON’Ts of Freeing?

A
  • Don’t free something that didn’t come from Malloc
  • Don’t free the same thing twice
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
75
Q

Does C have Classes?

A

No

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

What does C have instead of Classes?

A

Structs / Structures
{User-defined Data Types }

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

What does Struct do?

A

Groups Items of ‘Possibly’ differnet types into a single type

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

Format of Struct?

A

struct tag_name {
T1 member1;
T2 member2;
}tag_name;

// Need a separate function to initalsie the members in the struct

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

What is a Void Pointer?

A

Don’t know the type you want to point to

  • You have to cast the pointer to the correct type before you will use it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
80
Q

Format of a Function pointer?

A

type (*func) (arguments);

// func is a pointer to a function

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

What does scanf() do?

A

Takes Inputs until space

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

What does printf() do?

A

Outputs values

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

What does getchar() do?

A

Gets a Char from a Standard Input

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

What does putchar() do?

A

Writes a Char from a Standard Output

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

What is the getline() format?

A

getline(input, bufferSize, where its from)

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

What does getline() do?

A
  • Reads entire Line
  • Must be freed at the end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
87
Q

How to open a file in c?

A

FILE *fp ; // fp is a pointer to the type FILE

fp = fopen(“filename”,”mode”);

// must close it after use
close(fp)

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

What happens when fp = NULL in fopen?

A

It was unable to open the specified file

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

What is the function of File Read (R)?

A
  • File exists, opened as read-only
  • sets a pointer, that points to the first char
  • Else Errors
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
90
Q

What is the function of File Read (R+)?

A
  • Opens file for both reading & writing existing file
  • Does not delete the content of the existing file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
91
Q

What is the function of File Write (W)?

A
  • If the file exists it gets overwritten
  • Else creates a new one
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
92
Q

What is the function of File Write (W+)?

A
  • Opens a reading & writing a new file
  • Overwrite if file exists
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
93
Q

What is the function of File Appending (A)?

A
  • Opens file if it exits
  • Otherwise create a new one
  • Sets a pointer to the last char
  • New content appears after the old one
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
94
Q

What is the function of File Appending (A+)?

A
  • Open file for reading/writing from the last char in file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
95
Q

What does getc() do?

A

Reads a char from a file

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

What does putc() do?

A

Write a char to a file

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

What does fprintf() do?

A

Writes into file with file pointer

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

what does fscanf() do?

A

Reads into file with file pointer

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

What are possible Errors for Files in C?

A
  • Reaching beyond End-of-file
  • Uses a file that has not been opened
  • Opens a file with an invalid file name
  • Opens a file not permitted by fopen
  • Write to write-protected file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
100
Q

What is Random Access to File?

A

Can directly jump to a type byte-number in a file without reading previous data using fseek()

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

What does fseek(fp,-m,1)

A

Moves back by m bytes from the current byte

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

What does fseek(fp,m,0)

A

Moves to the m+1 th byte in the file

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

What are Command Line Arguments?

A

Arguments inputted on cmd line that the program has requested or been modified to recieve

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

What is argc?

A
  • An int
  • Stores the number of arguments on cmd line passed by user
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
105
Q

What is argv?

A
  • Argument Vector
  • Array of all the arguments (Excluding white space)
  • argv[0] – Name of program
    – argv[1] – 1st Argument
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
106
Q

What is a Makefile?

A
  • Compiles Multiple C files, along with additional steps to check for errors
  • Can also make warnings appear as errors as C has to be very accurate
  • Links all Files for full executable code.
  • Don’t need to compile code individually can be done all at once
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
107
Q

MakeFile Format?

A

<target>: <file0> <file1> ... <command></command>
</file1></file0></target>

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

Typical File Types in MakeFile

A
  • .c (for C)
  • .h
  • .o (Compiled Machine code)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
109
Q

What does preprocessor do in C?

A

Runs before compilation & does text situations

  • Like pasting file locations of the libraries
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
110
Q

What is a Macro?

A

USEFUL TO AVOID CALL OVERHEAD FOR SMALL FUNCTIONS BUT USE WITH CARE

  • If the function is going to be used multiple time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
111
Q

Format of Macro?

A

define MACRO(x) ((x) = (x) + 5 )

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

Format of Constant

A

define CONSTANTS 3.14159

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

What are Sockets?

A
  • Connects client to server
114
Q

Describe the socket’s function?

A
  • Behaves similar to files once connected (Read/Write)
  • Server binds to a port listens on the socket and accepts each client
  • Client connects IP/Port & read() & Write on socket
  • Socket must be closed after use
115
Q

Describe the multi-core system?

A
  • Each core has its own L1 cache
  • Some processors, each core has its own l2 cache
  • All cores share l3 cache
  • All cores share DDR RAM (Main Memory)
116
Q

What is the coherence of data?

A
  • Quality of being logical & consistent, during program execution, data remains coherent
  • On MCS, data variable may reside in multiple caches & updated locally, but its local core

-ERRORS cause coherence problems & protocols are needed

117
Q

What is a concurrent server?

A
  • Serves all clients at once, don’t need to wait for others to finish
  • All clients get served, even if one causes blocking, others don’t have to wait
  • All parallel tasks are concurrent, but concurrent tasks aren’t parallel
118
Q

What’s a Thread?

A
  • Thread of executions is the smallest sequence of programmed instructions
  • Managed independently by scheduler (part of OS)
  • Each Thread has its own copy of stack-related info
119
Q

Purpose of PThread?

A
  • Must link to the PThread library using compilation flag -lpthread file.c
  • Creates thread using pthread_create(), 0 if successful else non-zero
120
Q

What does PThread Contain?

A
  • Id of Thread
  • Constants that control thread attributes
  • Function(s) to be executed
  • Argument of Function
121
Q

How does Concurrent programming handle multiple arguments?

A
  • Packs arguments into a struct & creates a wrapper
  • Takes the compound argument & unpacks it
  • Passes unpacked arguments to a function
122
Q

Problem with Threads?

A
  • Can’t rely on all threads being executed
  • Add sleep function would make sure all threads are executed (BAD FIX)
123
Q

What are shared between concurrent threads?

A
  • Global data objects
  • Heap objects
  • Files
124
Q

What happens if the data objects are not shared?

A

Lack of sync leads to chaos and wrong calculations

125
Q

What are 3 ways to sync Threads?

A
  • Joins
  • Mutual Exclusion
  • Condition Variables
126
Q

What is JOINS?

A
  • Blocking function
  • Main only terminates when the 2 threads have joined
  • Both threads have been completed, But the order can change
  • Forgetting to join leaf to incorrect results
127
Q

What is the RACE CONDITION of JOINS?

A
  • RACE CONDITION: 2+ Thread perform operations on the same data, but the results are dependent on the order in which the operations are Performed
128
Q

What is Mutal Exclusion?

A
  • Mutex
  • Solves the race conditions of JOINS
  • Locks global resources until they get unlocked (Other locked threads will wait till the previous one is unlocked )
129
Q

How does Mutal Exclusion Resolve the JOINS Race condition?

A

Threads get exclusive access to shared resources in turn

130
Q

What are the Pitfalls of Mutual Exclusion?

A

2 Mutex Threads and lock both, will cause a deadlock and the code will hang forever

131
Q

What is trylock()?

A
  • Tries to lock mutex object
  • Return 0, if it can
  • otherwise non-zero & will not wait to be freed
132
Q

What are Condition Variables?

A
  • Used to sync threads based on the value of data
  • Waits till data reaches a particular value OR certain event occurred
    -Receiving signal, the waiting thread awakens (BASED ON CONDITION)
  • A thread goes to a waiting state based on ‘condition to happen’ by pthread_cond_wait(&condition_cond, &condition_mutex)
133
Q

What is the purpose of an Operating System?

A

A program that acts as an intermediary between a user of the computer and the computer hardware
OR
One program that is always running on the computer, with all else being systems programs & application programs

134
Q

What are the main functions of OS?

A
  • Resource Allocator
  • Control System
135
Q

What does the Resource Allocator do?

A

Manages all hardware resources & decides between conflicting requests for efficient & fair resources

136
Q

What does the Control System do?

A

Controls execution of programs to prevent errors & improper use of the computer

137
Q

What are the basic building blocks of OS?

A
  • Small bootstrap program is loaded at power-up or reboot (Stored in ROM or EPROM or firmware (BIOS))
138
Q

What does ROM stand for?

A

Read-Only Memory

139
Q

What does EPROM stand for?

A

Erasable Programmable ROM

140
Q

What are examples of firmware?

A

BIOS
(Basic, Input, Output, System)

141
Q

OS Sharing devices?

A
  • Device controllers are hardware within laptops/Comps
  • Bus connects CPUs, device controllers & Memory
  • OS kernel runs within the CPU & manages the device through the device controllers
142
Q

What are Device controllers?

A
  • I/O devices and CPU execute concurrently
  • Each device controller is in charge of a particular device type
  • Each has a local buffer
  • CPU moves data from buffers to main memory
  • I/O from device to local controller
  • Informs CPU that it has finished its operations via INTERRUPT
143
Q

What is an Interrupt Vector?

A

Reserved part of memory, tracking which interrupts need to be handled

144
Q

What is an Interrupt?

A
  • For each interrupt, the os executes the appropriate ISR to handle it
  • Address of Interrupt is saved so processing can carry on after completion of Interrupt
145
Q

How can software programs generate Interrupts?

A
  • Through System cells (Like when an error occurs)
  • Software-generated interrupt is called a TRAP
146
Q

What is Main Memory?

A
  • Large storage that the CPU can access directly
  • Volatile (Memory not saved when laptop turned off)
  • RAM
147
Q

What is Secondary Storage?

A
  • Large non-volatile storage
  • (Flash memory, Magnetic Disk & CDs)
148
Q

What are the services of OS?

A
  • UI
  • Processes
149
Q

What is UI?

A
  • Interact indirectly through a collection of system programs that make up the OS interface
  • GUI: icons & windows
  • CMD interface running processes and scripts
150
Q

What are Processes?

A
  • Interact with the OS by making system calls into the OS kernel
    - For stability, such calls are to be directed to the Kernel Function
151
Q

What are EGs:

A
  • Program Execution:
    • System must be able to load a program into memory and run that program
    • End execution, either normally or abnormally (indicating error)
  • I/O Operations:
    • A running program may require I/O, which may involve file or an I/O device
  • File-system manipulation:
    • Programs need to read and write files & directories
    • Create, Delete & Search them, list file info & permission management
  • Interprocess Communication (IPC):
    • Allowing the process to share data through message passing or shared memory
152
Q

What are services for OS?

A
  • Error Handling:
    • What if our process attempts a div 0 or tries to access a protected memory region / if a device fails?
  • Resource Allocation:
    • Processes may be completed for resources such as the CPU, memory, and I/O devices
  • Accounting:
    • How much disk space is this or that user using? how much network bandwidth are we using?
  • Protection & Security:
    • The owners of info stored in a multi-user networked computer system may want to control the use of that info. &concurrent processes should not interfere with each other
153
Q

What are OS Architecture?

A
  • UNIX - One big Kernel
    • Consists of everything below the system call interface & above the physical hardware
    • Provides the file system, CPU scheduling, memory management,& other FUNCs; Large No. functions for 1 level
    • Limited to hardware support compiled into the kernel
154
Q

What are System Calls?

A
  • Programming interface to the service provided by the OS
    (Open file, read file, etc.)
  • Typically Written in C/C++
  • Accessed by programs using High-level APIs
  • APIs allow application code to access the kernel without requiring required root privileges
    (Controls from user mode to kernel mode)
155
Q

What are common APIs in System Calls?

A
  • Win32 for windows
  • POSIX API for UNIX-based system
156
Q

System Calls for Open File Operation?

A
  • Register the file with the os
  • Called before any operations on the file
  • Returns an Integer called the file descriptor
    (Index into the list of open files maintained by os)
157
Q

System Calls for Read File operation?

A
  • Read data from the file
  • Returns No. of bytes read of 0 for EOF
158
Q

System Calls for Write File operation?

A
  • Write data to a file. Returns No. of bytes written
159
Q

System Calls for Close File Operation?

A
  • De-register the file with the OS
  • No further operations on the file are possible
160
Q

What does the System Calls return when an error occurs?

A
  • These system calls return a -ve NO. on error

can use terror-function to display error

161
Q

What is Trapping Kernel?

A
  • User process calls the system call wrapper function from the standard c library.
  • Wrapper Function issues low-level trap instructions to switch from user mode to kernel mode
  • Some function calls may take arguments, which may be passed as pointers to struct via registers
162
Q

How to fix the issue that no call can be made directly from user space to a specific function in the Kernel space?

A
  • Issue the trap instructions, an index is stored in a well-known location
  • Once switched into kernel space, the index is used to look up the desired kernel service function, which is then called
163
Q

Modular Kernel Implementation?

A
  • Most modern OS implement Kernel modules
    • Object-oriented approach
    • Each core component is separate
    • Each talk to the others over known interfaces
    • Each is loadable as needed within the kernel. Download a new device driver for your OS & load it at run-time or perhaps when the device is plugged in,
164
Q

What is a Modular Kernel?

A
  • Similar to layered architecture but with flexibility
    (All drivers or kernel functionally do not need to be compiled into kernel binary)
  • Separation of the modules is still logical since all kernel code runs in the same privileged address space
    (Writes a module that wipes out the os with no problem )
    (Leads to the benefits of microkernel )
165
Q

What’s in the kernel core?

A
  • Device & Bus Drivers
  • Scheduling Classes
  • File Systems
  • Loadable System Class
  • Executable Formats
  • Streams Module
  • Miscellaneous Modules
166
Q

What is a Microkernel?

A
  • Moves as much as possible from the kernel into less privileged ‘user space’
  • Comms take place between user modules using message-passing
  • Hard disk device can run all logic in user space
  • When it needs to talk directly to hardware using privileged I/O port instructions, must pass a message requesting such to the kernel
167
Q

Give 3 Benefits of Microkernel?

A
  • Easier to develop microkernel extensions
  • Easier to port OS to new architecture
  • More reliable (Driver fails, it gets reloaded)
  • More secure, the kernel is less complete & less likely to have security holes.
  • System can recover from a failed device driver.
    (Cause “blue screen of death” in windows )
    ( “Kernel Panic” in Linux)
168
Q

Give a Drawback of Microkernel?

A
  • Overhead of user space or kernel space communication
  • Linux OS & L3/L4 are examples of microkernel architecture
169
Q

What is a Virtual Machine?

A
  • VM allows to run one OS (GUEST) on another OS (HOST)
  • VM provides an interface identical to the underlying bare hardware
  • OS host creates the illusion that a process has its processor & VM
  • Each guest is provided with a virtual copy of the underlying computer. So it is possible to install
170
Q

VM History?

A
  • Appeared in IBM mainframes in 1972
  • Multiple execution environments can share the same hardware
  • Protected from one another, so no interference:
    • some sharing of files can be permitted, controlled
    • Comms with one another & with other physical systems via networking
171
Q

Pros of VM?

A
  • Used for development, and testing, due to easy reversal accidentally destroyed OS back to previous state
172
Q

What is the Open Virtualisation Format?

A

The standard format of VM, which allows it to run within many different VM Platform

173
Q

Differences in Emulation & OVF?

A
  • Emulation guest instructions run within a process that pretends to be the CPU
  • OVF, the goal is to run guest instructions directly on the host CPU
    (This means the guest OS must run on the CPU architecture of the host )
174
Q

What is para-virtualisation?

A
  • Presents guests with system similar but not identical hardware
  • Guest OS must be modified to run on para-virtualisation ‘hardware’.
175
Q

How is para-virtualisation hardware modified?

A
  • Kernel is recompiled with all code that uses privileged instructions replaced by hooks into the virtualization layer
  • OS has been successfully modified, para-virtualisation is very efficient & is often used for providing low-cost rented Internet services
176
Q

What is VMWare Architecture?

A
  • Implements full virtualisation, such that guest OS don’t require modification to run upon the VM
  • VM & must convince the guest that it is running privileged CPU when it’s not
    (Scenario - a process of the guest OS raises div 0)
177
Q

What are device drivers?

A

Software that allows other programs to interface with external devices through the device controllers.

(Run in kernel mode, device management software may well run in user mode typically these wouldn’t be called ‘drivers’)

178
Q

What does OPEN do in System Calls?

A

Make device available

179
Q

What does READ do in System Calls?

A

Read from device

180
Q

What does WRITE do in System Calls?

A

Write to device

181
Q

What does IOCTL do in System Calls?

A

Perform operations on devices

182
Q

What does CLOSE do in System Calls?

A

Make devices unavailable

183
Q

What is Kernel Side?

A

Each file may have a function associated with it which is called when corresponding system calls are made.

linux/fs.h lists all available operations on files

184
Q

How are Devices Categorised?

A

Physical Dependencies:
Between devices (Connected to USB-hub)
Buses:
Channels between processors & 1 or more devices (PHYSICAL OR LOGICAL)
Classes:
Set of devices of the same type (e.g keyboards or mice)

185
Q

How are Interrupts handled in Device Drivers?

A
  • Device sends interrupt
  • CPU selects the appropriate interrupt handler
  • Interrupt handler processes
186
Q

What 2 important tasks does the Interrupt handler process?

A
  • Data to be transferred to/from device
  • Waking up processes which waits for data transfer to be finished
  • Interrupt handler clears interrupt but of the device necessary or next interrupt to arrive
187
Q

How important is the Interrupt Processing Time?

A
  • Must be fast
  • Data transfer is fast, the rest of the processing is slow
188
Q

What are the 2 Halves of the interrupt?

A

Top Half:
- Directly by the interrupt handler
- Only transfers data between the device & appropriate kernel buffer & scheduler software interrupts to start the bottom half

Bottom Half:
- Runs in Interrupt context & does the rest of the processing
(Working through protocol stack & waking up process)

189
Q

What is Memory Management?

A

Management of a limited resource
- Sophisticated algorithms needed, together with support from HW & the compiler & Loader

  • Want to be able to store the memory of several programs in main memory at the same time.
190
Q

Key Point for Memory Management?

A

The program’s view memory is a set of memory cells at address 0x0 & finishing at some val (LOGICAL ADDRESS)

191
Q

Hardware for Memory Management?

A

Set of memory cells starting at address 0x0 & finishing at some val (PHYSICAL ADDRESS)

192
Q

What is a suitable mapping from logical to physical addresses?

A
  • Compile Time:
    Absolute references are generated
  • Load Time:
    This can be done by a Special Program
  • Execution Time:
    Needs Hardware support
  • Dynamic Linking:
    Use only one copy of the system library
    OS has to help: the same code accessible to more than one process
193
Q

What is External Fragmentation?

A

Small holes appear in memory overtime

194
Q

What is Internal Fragmentation?

A

Programs are only a little smaller than the hole, so the leftover is too small to qualify as a hole

195
Q

What is Swapping?

A
  • Memory Management Technique
  • Too high memory demand: Memory of some processes is transferred to disk
  • Combined with scheduling, low-priority processes are swapped out
196
Q

Problems of Swapping?

A
  • Big Transfer Time
  • What to do with pending I/O
  • Not principal memory management technique
197
Q

Strategies for Choosing Holes?

A
  • First-fit
  • Rotating First Fit
  • Best Fit
  • Buddy System
198
Q

What is First-fit?

A

Start from the beginning & use the first available hole

199
Q

What is Rotating First Fit?

A

Start after the last assigned part of memory

200
Q

What is the Best Fit?

A

Find the smallest usable space

201
Q

What is the Buddy System?

A
  • Holes in size of power of 2
  • Smallest possible hole used
  • Split the Hole in 2 if necessary
  • Recombine 2 Adjacent Holes of the same size
202
Q

What is Paging?

A
  • Assigns Memory of a fixed size (PAGE)
  • Motivated by ease of allocation
  • Avoid external fragmentation
  • Translation of logical address to physical address done via page table
  • Motivated by ease of allocation
203
Q

What hardware support is Mandatory for Paging?

A
  • Small Page Tables
    • Fast Registers
  • Large Page Tables
    • Stored in Main Memory
    • Caches most recent entry
      (Instance of general principle )
204
Q

How is memory protected in paging?

A

Info stored in a page table

205
Q

What is Segmentation?

A

Divides memory according to its usage by programs

Data: mutable, different for each instance
Program code: immutable, same for each
instance
Symbol Table: immutable, same for each
instance, only necessary for
debugging

Requires Hardware support
Can use some principles such as paging, however, must do an overflow check

  • Motivated by the use of memory
206
Q

What is Virtual Memory?

A

Complete separation of logical & physical memory

Works due to programs using a small fraction of this memory

207
Q

What is the problem with Virtual Memory?

A

Enormous difference between memory access speed & disk access speed

208
Q

What is Demand Paging?

A
  • Virtual Memory implemented as demand paging
  • Memory divided into same-size pages, with valid/invalid bit
209
Q

What is a Swapper?

A

‘Swap out’ process (move whole memory to disk & block process)

210
Q

What is a Pager?

A

‘Which pages to move’ when the move is needed

211
Q

Why is it crucial to have a minimal rata of page faults?

A

10% slowdown due to page fault, then fault rate:

- HHD:
     p < 10^(-6)
- SSD
     p < 10^(-4)
212
Q

What are the 2 Strategies made in Demand paging?

A

Pager & Swapper

213
Q

What are Page replacement Algorithms?

A
  • First In First Out
  • Optimal Algorithm
  • Least-Recently Used
214
Q

What is First In First Out?

A
  • Easy to implement
  • Doesn’t take locality into account
  • An increase in the number of frames can cause an increase in the number of page faults
215
Q

What is an Optimal Algorithm?

A
  • Select a page which will be reused at the latest time
216
Q

What is the Least-Recently Used Page Replacement method?

A
  • Past as a guide for future
  • Replace the page which has been unused for the longest time
217
Q

What is a CON for Least-Recently used?

A

Requires a lot of hardware support

218
Q

What are the possibilities for page replacement algorithms?

A
  • Stack in Microcode
  • Approx. using reference bit: Hardware sets the bit to 1 when bit is referenced
219
Q

What is the second Chance algorithm?

A

FIFO

220
Q

What replacement algorithm should you use?

A

FIFO, but it skips reference bit 1 & resets them to 0

221
Q

What is Thashing?

A
  • Page fault rate is high, when the process locks frames it constantly uses
    Thus:
    • CPU throughput decreases dramatically
    • Disastrous effect on performance
222
Q

What are the 2 solutions for Thrashing?

A
  • Working-set model (BASED ON LOCALITY)
  • Page Fault Frequency (Direct approach )
223
Q

What is the Working set Model?

A
  • Define working set as a set of pages used in the most recent page reference
  • Only working set in Main Memory is Kept (Achieves High CPU- utilisation & prevents thrashing )
224
Q

For the working set what is the Difficulty?

A

Determining the Working set

225
Q

What is the Approximation for the working set?

A

Use reference bits; copy each 10,000 references & define the working set as pages with reference bit set

226
Q

What is the Page-Fault Frequency?

A
  • Give process additional frames if the page frequency rate high
  • Remove the frame from the process if page fault rate is low
227
Q

What is Memory Management in Linux Kernel?

A
  • 4 Segments in Total:
    • Kernel Code
    • Kernel Data
    • User Code
    • User Data

Uses paging, but has an elaborate permission system for pages

Separate Logical address for kernel & user memory

228
Q

What is 32-bit architectures (4GB Virt Mem)?

A
  • Kernel space address is the upper 1GB of address space
  • User space address is the lower 3GB
  • Kernel Memory is always mapped, but protected against access by user process
229
Q

What is the 64-bit architecture?

A
  • Kernel space address and user space address are split in half
230
Q

What are Page Caches?

A
  • Repeated cycles of allocation & freeing of the same kind of object can have a pool of pages used as a cache for these objects
  • Cache maintained by application
  • kmalloc uses slab caches from commonly used size
231
Q

Give a Summary of Device Drivers:

A

Implement open, read, write & close with common structure

232
Q

Give a Summary of Memory Management:

A
  • Management of limited resources -> serious effort required
  • Need to isolate memory for each process
  • Memory demand too high, need to swap out part of the memory of the process (PAGING / SEGMENTATION achieves this )
  • Requires Hardware support
233
Q

What is Kernel Programming?

A
  • Has access to all resources
  • Programs not subject to any constraints from memory access or hardware access
234
Q

What is the result of Faulty Programs?

A

System Crash

235
Q

What are System Calls?

A

The kernel provides its function only via special functions

This is provided by Standard C library

236
Q

Does there have to be a strict separation of kernel data & data for user programs?

A

YES
(Explicit copying between user program & kernel)

237
Q

What functions are used for strict separation?

A
  • copy_to_user()
  • copy_from_user()
238
Q

How do Interrupts work in Kernel?

A
  • Asks Hardware to perform a certain action
  • HW sends an interrupt to the kernel which performs desired action interrupts must be processed quickly
    (Any code called from interrupt must not sleep)
239
Q

What are the 2 Main Modes for kernel code?

A
  • Process Context
  • Interrupt Context
240
Q

What is Process Context?

A

Kernel code works for user programs by executing a system call

241
Q

What is Interrupt Context?

A

Kernel code handling an Interrupt (by a device)

  • Have access to user data only in process context
  • Any code running in process context may be pre-empted at any time by an interrupt
  • Interrupt has priority levels
    (Higher ones pre-empt low priority)
242
Q

What are Kernel Modules?

A
  • Add code to the running kernel
  • Useful for providing device drivers which are required only if hardware is present
243
Q

What is modprobe?

A

Inserts module into running kernel

244
Q

What is rmmod?

A

removes modules from running kernel

245
Q

what is lsmod?

A

List Currently running module

246
Q

Why is concurrency handling important?

A
  • Manipulation of data structures which are shared between
    • code running in process mode & code running in interrupt mode
    • code running in interrupt mode
  • Happens only with critical regions
    - Multi-processor system manipulation of data structure shared between code running in process context must happen only within a critical section
247
Q

What are 2 ways to achieve Mutual exclusion?

A
  • Semaphores/Mutex
  • Spinlocks
248
Q

What is Semaphores?

A
  • Entering the critical section fails, the current process is put to sleep until the critical region is available
  • Only usable if all critical regions are in process context
249
Q

What are the Semaphore Functions?

A
  • DEFINE_MUTEX()
  • mutex_lock()
  • mutex_unlock()
250
Q

What is Spinlocks?

A
  • Processor tries repeatedly to enter the critical section
  • Usable anywhere
251
Q

What are the disadvantages of Spinlocks?

A

Have busy waiting

252
Q

What are the Spinlock Functions?

A
  • spin_lock_init()
  • spin_lock()
  • spin_unlock()
253
Q

What are the 2 Kinds of Semaphores?

A
  • Normal Semaphores
  • Read-Write Semaphores
254
Q

What is a Read-Write Semaphore?

A

It is useful if some critical region only reads shared data structs & this happens often

255
Q

Explain how the Programming data transfers between userspace & Kernel?

A
  • Linux maintains a directory called proc as an interface between user space & kernel
  • Files in this directory do not exist on the disk
  • Read & Write operations on these files translate into kernel operations, together with data transferred between user space & kernel
  • Useful mechanism for info exchange between kernel & user space
256
Q

What are the major parts of the Kernel?

A

DEVICE DRIVERS :
- subdirectory drivers, sorted according to category
FILE SYSTEM:
- In subdirectory fs
SCHEDULING & PROCESS MANAGEMENT:
- In subdirectory Kernel
MEMORY MANAGEMENT:
- In subdirectory mn
NETWORKING CODE:
- In subdirectory net
ARCHITECTURE SPECIFIC LOW-LEVEL CODE:
- In subdirectory arch
INCLUDE-FILE:
- In the subdirectory include

257
Q

What is the variety of programs the OS executes?

A

BATCH SYSTEM:
- jobs
TIME-SHARED SYSTEMS:
- User programs/tasks
PROCESS:
- A program in execution
- Execution must progress in a sequential fashion

258
Q

What do processes include?

A
  • Program
  • Stack
  • Program Counter
  • Data Section
259
Q

What are the 5 Process States?

A
  • NEW (Process is being created)
  • READY (The process is waiting to be assigned to a processor)
  • WAITING (Process is Waiting for some event to occur)
  • RUNNING (Instruction is being executed)
  • TERMINATED (Process has finished execution)
260
Q

What states go to NEW state?

A

NONE

261
Q

What states go to READY State & HOW?

A
  • NEW (admitted)
  • WAITING (I/O or Event Completion)
  • RUNNING (Pre-empted)
262
Q

What states go to RUNNING State & HOW?

A
  • READY (Scheduler Dispatch)
263
Q

What states go to WAITING State & HOW?

A
  • RUNNING (I/O or Event Wait)
264
Q

What states go to TERMINATED State & HOW?

A
  • RUNNING (Exit)
265
Q

What is a Process Control Block?

A
  • Info associated with each process, which is stored as various fields within kernel data:
  • PROCESS STATE
  • PROGRAM COUNTER
  • CPU REGISTERS
  • CPU SCHEDULING INFO
  • MEMORY MANAGEMENT INFO
  • ACCOUNTING INFO
  • I/O STATUS INFO
266
Q

How are Process Created?

A
  • Parent process creates the children process, which creates other methods, making a tree of processes
267
Q

What is PID and what does it stand for?

A

PID (Process Identifier)
- Identifies & Manages Processes

268
Q

How does resource sharing between parent and child process?

A
  • Parent & Child share all resources
  • Child share subset of parent’s resources
  • Share no resources
269
Q

How are parent & child executed?

A
  • Parent & Child execute concurrently
  • Parent wairs until terminates

Up to the compiler whether it executes the parent/child process

270
Q

Give an example of how the Processes work.

A
  • Fork system call creates a new process
  • exec system call used after a fork to replace the process’ memory space with a new program
271
Q

Explain process termination?

A

Executes last statement & asks OS to delete it (EXIT)
- Output data from child to parent
- Resources are deallocated by OS

A parent may terminate the execution of the Child Process (ABORT)
- Child exceeded allocating resources
- Task assigned to a child no longer required

  • Parent Exiting:
    Some OS doesn’t allow the child to continue if its parent terminates - all children terminated (CASCADING TERMINATION)
272
Q

Explain Concurrency through Context Switching?

A
  • CPU switches to another process, the system must save the state of the old process & load the saved state for a new process via context switching
  • Context of process represented in PCB
  • Context - Switch is overhead; the system does no useful work while switching
  • Time-dependent on hardware support
273
Q

What is the problem with scheduling?

A
  • Processes Competing for resources
  • Import OS functions: define a schedule to manage access of process to these resources
  • Done by having queues of processes waiting for specific resources & selecting a process in a queue.
274
Q

Give the 3 Scheduling Queues.

A
  • Job Queue
  • Ready Queue
  • Device Queue
275
Q

What is the Job Queue?

A
  • Set of all processes in the system
276
Q

What is the Ready Queue?

A
  • Set off all processes residing in Main Memory, ready & waiting to execute
277
Q

What is the Device Queue?

A
  • Set of processes waiting for l/O devices
278
Q

Can Processes migrate among various queues?

A

YES

279
Q

What are the Prerequisites for successful scheduling?

A

CPU-I/O-Burst Cycle:
- I/O occurs after a fixed amount of time greater than or equal to 90%
- Appropriate time for rescheduling

Preemptive Scheduling:
- Process can be forced to relinquish the processor

280
Q

What are the Scheduling Criteria?

A
281
Q

Why do we have the Scheduling Criteria

A