Podcast
Questions and Answers
In the context of operating systems, the kernel is often compared to the 'brain' of a computer. Which of the following analogies most accurately reflects the kernel's role in a modern, complex system?
In the context of operating systems, the kernel is often compared to the 'brain' of a computer. Which of the following analogies most accurately reflects the kernel's role in a modern, complex system?
- A high-frequency trading algorithm, reacting instantaneously to market changes without needing a comprehensive understanding of global economics.
- The electrical grid of a city, distributing power to various sectors but unaware of the specific appliances being powered.
- The engine control unit (ECU) in a modern automobile, managing all sensor data, actuator controls, and safety systems to ensure optimal performance.
- A project manager within a large construction firm, delegating tasks to specialized teams and ensuring adherence to the architectural blueprint. (correct)
In C, accessing argv[argc]
will always result in a segmentation fault due to out-of-bounds access.
In C, accessing argv[argc]
will always result in a segmentation fault due to out-of-bounds access.
False (B)
Explain the security implications if a system's /tmp
directory is mounted with the noexec
option inadvertently disabled.
Explain the security implications if a system's /tmp
directory is mounted with the noexec
option inadvertently disabled.
If /tmp
's noexec
is disabled, it allows execution of arbitrary code placed in the directory. This can be exploited by attackers to run malicious scripts or binaries, potentially leading to system compromise through privilege escalation.
In the context of memory management in C, the function ______
is specifically designed to change the size of a previously allocated memory block.
In the context of memory management in C, the function ______
is specifically designed to change the size of a previously allocated memory block.
Match the following Linux commands with their specific functions related to file system operations:
Match the following Linux commands with their specific functions related to file system operations:
Given the command gcc -o myprogram source.c -lmath -dynamic
, what is the most accurate interpretation of the -dynamic
flag's impact on the resulting executable?
Given the command gcc -o myprogram source.c -lmath -dynamic
, what is the most accurate interpretation of the -dynamic
flag's impact on the resulting executable?
In a system utilizing Position Independent Executables (PIE), the base address of the executable is fixed at load time, providing no ASLR benefits.
In a system utilizing Position Independent Executables (PIE), the base address of the executable is fixed at load time, providing no ASLR benefits.
Describe the potential consequences of using strcpy
inappropriately when handling user-supplied input in a C program.
Describe the potential consequences of using strcpy
inappropriately when handling user-supplied input in a C program.
In the x86-64 architecture, the register typically used to pass the first floating-point argument to a function, conforming to the System V AMD64 ABI, is ______
.
In the x86-64 architecture, the register typically used to pass the first floating-point argument to a function, conforming to the System V AMD64 ABI, is ______
.
Match the memory region with its primary purpose in a typical Linux process:
Match the memory region with its primary purpose in a typical Linux process:
Consider a scenario where a multi-threaded C application is experiencing performance bottlenecks due to excessive contention. Which of the following strategies would be MOST effective in mitigating these issues at design level?
Consider a scenario where a multi-threaded C application is experiencing performance bottlenecks due to excessive contention. Which of the following strategies would be MOST effective in mitigating these issues at design level?
The primary advantage of using memory-mapped files over traditional read/write operations is that memory-mapped files always result in lower memory consumption.
The primary advantage of using memory-mapped files over traditional read/write operations is that memory-mapped files always result in lower memory consumption.
Explain the concept of 'thundering herd' in the context of concurrent programming and describe a technique to alleviate it.
Explain the concept of 'thundering herd' in the context of concurrent programming and describe a technique to alleviate it.
In the context of C++, the ______
keyword is used to prevent a virtual function from being overridden in derived classes, effectively finalizing the method in the inheritance hierarchy.
In the context of C++, the ______
keyword is used to prevent a virtual function from being overridden in derived classes, effectively finalizing the method in the inheritance hierarchy.
Match the common CPU vulnerabilities with their corresponding mitigation techniques:
Match the common CPU vulnerabilities with their corresponding mitigation techniques:
What is the most accurate description of the potential impact of memory fragmentation on a long-running server application?
What is the most accurate description of the potential impact of memory fragmentation on a long-running server application?
In C, the volatile
keyword guarantees atomicity of read and write operations on a variable across all architectures.
In C, the volatile
keyword guarantees atomicity of read and write operations on a variable across all architectures.
Explain the difference between a preemptive and a non-preemptive (cooperative) multitasking operating system, highlighting a potential disadvantage of non-preemptive multitasking.
Explain the difference between a preemptive and a non-preemptive (cooperative) multitasking operating system, highlighting a potential disadvantage of non-preemptive multitasking.
In the context of distributed systems, the CAP theorem states that it is impossible for a distributed data store to simultaneously provide more than two out of the following three guarantees: Consistency, Availability, and ______
.
In the context of distributed systems, the CAP theorem states that it is impossible for a distributed data store to simultaneously provide more than two out of the following three guarantees: Consistency, Availability, and ______
.
Match the Inter-Process Communication (IPC) mechanism with its characteristic:
Match the Inter-Process Communication (IPC) mechanism with its characteristic:
Flashcards
What is the kernel?
What is the kernel?
The core of the OS; like the brain, it manages the system's functions.
Kernel functions
Kernel functions
Acts as the medium between hardware and software, manages memory and processes.
What is a filesystem?
What is a filesystem?
A structure that organizes files. Root is represented by /.
ls Command
ls Command
Signup and view all the flashcards
cd Command
cd Command
Signup and view all the flashcards
mkdir Command
mkdir Command
Signup and view all the flashcards
What does sudo do?
What does sudo do?
Signup and view all the flashcards
What is gcc?
What is gcc?
Signup and view all the flashcards
What does -o do in gcc?
What does -o do in gcc?
Signup and view all the flashcards
How a program sees memory
How a program sees memory
Signup and view all the flashcards
Memory Organization
Memory Organization
Signup and view all the flashcards
What is the heap?
What is the heap?
Signup and view all the flashcards
What is the stack?
What is the stack?
Signup and view all the flashcards
Program address space
Program address space
Signup and view all the flashcards
Static vs Shared?
Static vs Shared?
Signup and view all the flashcards
C variable Types
C variable Types
Signup and view all the flashcards
How C handles overflow
How C handles overflow
Signup and view all the flashcards
printf() and scanf()
printf() and scanf()
Signup and view all the flashcards
& operator in C
& operator in C
Signup and view all the flashcards
#include does what?
#include does what?
Signup and view all the flashcards
Study Notes
General Notes
- The midterm will be fully comprehensive of covered content
- Review labs and class codes, since there will be no questions from zybooks
- Code understanding is necessary; code writing is not
- The exam includes ~30 multiple choice and ~5 open-ended questions, testing theoretical and practical knowledge
Lecture 1: Kernel, Filesystem, and Linux Commands
- The kernel is like the brain of a computer system that performs many functions
- Kernel functions include acting as a medium between HW and SW, memory/process/input-output/file system management
- The root of the filesystem is represented by a forward slash (/)
- The filesystem has a tree representation
- The computer organizes and accesses files through the filesystem
Common Linux Commands
ls
: Lists directory contentscd
: Changes the current directorymkdir
: Creates a new directorymv
: Moves or renames files or directoriescp
: Copies files or directoriesscp
: Securely copies files between hoststar
: Archives filesrm
: Removes files or directorieschmod
: Changes file permissionscat
: Concatenates and displays filesgrep
: Searches for patterns in filesless
: Views file contents page by pagemore
: Displays file contentsman
: Displays the manual page for a command
Sudo and GCC
sudo
stands for "Super User Do", and provides elevated privileges to run commandsgcc
is a built-in compiler, part of the GNU Compiler Collection, and compiles source code into machine codegcc -o <output_file name> <source_file.c>
compiles code with GCC-o
specifies the output file name during GCC compilation
Lecture 2: Memory Organization
- A program sees memory as an array of bytes in the range of 0 to 2^64 - 1
- Memory is organized into sections known as memory mappings
Memory Sections
- TEXT stores instructions that the program runs
- DATA stores initialized global variables
- BSS stores uninitialized global variables, initialized to zeros until assigned a value
- HEAP stores memory returned by
malloc/new
- STACK stores local variables and return addresses
- Shared libraries (.so files) are not added to the executable, consist of definitions only, and are dynamically loaded at runtime
Heap and Stack
- The heap is a space for dynamic memory allocation that grows upward
- The stack stores local variables and grows downwards
Program Memory
- Each program has an independent view of memory
- There could be memory gaps without memory mapping between each section
- If a program tries to access a memory gap, the OS sends a SEGV signal which terminates the program and dumps a core file
Static and Shared Libraries
- Static libraries are not shared, with an instance per process, and represented as (.a) files added to the executable
- Shared libraries are shared across different processes, with only one instance for the entire system
Events
- Static events occur during program building
- Dynamic events occur while the program is running
C Variable Types
- Common variable types in C :
int
,char
,double
,pointer
,string
,float
,short
,long
,unsigned
Integer Overflow
- C handles integer overflow by conducting two's complement, wrapping back to the beginning of the value range
- Inputting 2,147,483,648 results in an output of -2,147,483,648
Lecture 3: Printf, Scanf, and Preprocessor Directives
printf()
prints variables and expressions to standard output (terminal)scanf()
takes input from standard input (console)- The
&
operator is the address-of operator - When paired with a variable,
&
acquires the memory address %
(percent sign) is the format specifier for printing and scanning#include
declares preprocessor directives for libraries or files intended for utilization#define
is a preprocessor directive that creates macros- Macros are constant values or expressions substituted into code before compilation
Lecture 4: Ternary Expressions
- Ternary expressions are single-line if-else statements
- The two symbols used in ternary expressions are
?
and:
?
can be considered "then" and:
can be considered "otherwise"variable = (condition) ? Expression2 : Expression3
and(condition) ? (Expression2) : (Expression3)
are both ways to read a ternary expressionvariable = Expression1 ? Expression2 : Expression3
is also a way to read a ternary expression
Lecture 5: Functions
- Functions are blocks of code performing specific tasks when called
- Functions consist of a declaration, definition, and call
- A function prototype tells the compiler about a function's existence and how it can be called
- If a function is not defined at the top of the code, an implicit declaration warning is given and a function prototype should be used
Passing by Value vs. Reference
- Passing by value copies the values to function parameters, creating new memory
- Passing by reference allows functions to operate on the original data
- Pass by reference is useful when modifying variables or avoiding copying large data structures
Recursion
- Recursion is a technique where a function calls itself
- Recursion breaks down complex problems into simpler ones
Lecture 6: Pointers
- A pointer is a variable that points to an address in memory
- A pointer occupies 8 bytes in a 64-bit system and 4 bytes in a 32-bit system
- An integer occupies 4 bytes and a character 1 byte in a 64-bit system
*
is the dereference operator and accesses data stored at a memory address- Pointers store a memory address
int *ptr = &var
initializes a pointer to point at the memory address ofvar
ptr
alone produces the memory address ofvar
*ptr
produces the value residing at the memory address ofvar
Pointer Arithmetic
(*ptr)++
dereferences the pointer first and adds 1 to the value*ptr++
moves to the next memory address- Unary operators are read right to left
Double Pointers
- A double pointer stores the memory address of another pointer
- Double pointers help manage dynamically allocated memory, pass pointers to functions, or deal with complex data structures
Code Example
- In the code, a
var
is allocated an assiged the value 10.ptr
( a pointer) , is initialized and assigned the memory address ofvar
,. anddptr
(a double point) is initialized and assigned to the memory address ofptr
- If
dptr
is dereferenced twice, the contents ofvar
is accessed
Array Decay
- When passing an array to a function, array decay occurs which means the array name decays into a pointer to the first element
- Instead of copying the entire array, the memory address of the first element is passed
Array Size
- To pass an array to a function you must include the size of the array
Sizeof()
sizeof()
returns the total number of bytessizeof()
is used to determine the size of an arraysizeof(array) / sizeof(array[0])
formula gets the actual size of the array
Arrays and Pointers
- Passing an array to a function passes the memory address of the first element, turning the array into a pointer
Array Iteration
- Arrays can be iterated over with pointer arithmetic by adding a value to move
x
positions through the array - To move and access data within the array you must encapsulate the pointer and the value like so
*(ptr + 2)
Lecture 7: Stack
- The stack stores information for passing control and data and allocating memory
- The stack stores function local, temporary, and return variables, as well as arguments for the next function call
- The stack adds data with push and removes data with pop
Compiler Stack Management
- The compiler utilizes the stack as follows
- Allocates one stack frame each time a function is called or exits
- Stacking frames on top or under one another
- Stack frames are created and destroyed when a function is called and at function exit
Potential Stack Issues
- The stack can run out of stack space
- There is potential to unintentionally change values on the stack such as, functions, variables, the return address of a function
- It can access memory, even after the frame is deallocated
- When it runs out of space the program will crash because of a segmentation fault or stack overflow error
Buffer Overflow
- A buffer overflow occurs when more data than anticipated is placed by a program or system process on the stack, causing excess data to overflow
Lecture 8: Malloc, Memory Allocation, and Pointers
- Pointers are more efficient for array indexing because multiplication is not required to find the correct index
malloc
dynamically allocates a single large block of memory with a specified size and the memory allocated by malloc is stored in the heap, and returns a pointer to a suitably aligned memory block- A pointer type cast is needed to be able to appropriately cast the pointer data, since the
malloc
function returns a pointer to void - A pointer in a 32-bit system is 4 bytes
Memory Deallocation
- Memory allocated by
malloc
orcalloc
can be deallocated with free, preventing memory leaks - Memory leaks are objects in memory no longer in use, but not freed
Memory Issues
- Failing to deallocate memory results in memory leaks
- You can run out of space in the heap and
malloc
returns 0 - You can unintentionally change other heap data by clobbering the data, which means a registers if overwritten during execution
- You can access or free memory twice which can cause crashing or memory corruption of the heap, creating a memory leak
Lecture 9/10: Memory relationships
- Assuming "int a[20]", then A[i] is equivalent to *(a+i), which is equivalent to *(&a[0]+i)
Lecture 11: Memory management
- A premature free occurs when an object, still in use, is freed by the program
- A double free happens when an object that is already free is again freed
- Wild frees are a result of attempting to free memory that was not returned by
malloc
- Memory smashing occurs when less memory is allocated than will be used
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.