This is a general outline of the key concepts (arranged by topic) that you should know for the Exam 03.
The exam will have the following format:
Code Snippets: Evaluate or write Shell commands or Python code to perform certain tasks. (6 Points)
Short Answers: Briefly answer questions about:
Unix Philosophy (3 Points)
Data Representation (6 Points)
Data Structures (6 Points)
Memory Errors (5 Points)
I/O, Files, Directories (5 Points)
Processes (6 Points)
Networking (6 Points)
Programming: Write some C code that uses system calls. (9 Points)
Parts 1 and 2 are to be done first on paper. After these parts are completed, part 3 can be done with the aid of your laptop and the Internet (but not other people).
The final exam will be a comprehrensive assessment. This means that everything we have discussed this semester is considered fair game.
That said, the majority of the test will cover the last half of the class, as detailed below.
What is Unix?
What are the three tenets of the Unix Philosophy?
What are filters? What do they do and how are they related to the Unix Philosophy?
What are the principles of functional programming?
How does functional programming compare to procedural programming?
How is functional programming related to the Unix Philosophy?
What is concurrency and what is parallelism?
What makes concurrency challenging?
What are the different forms of parallelism?
How do you construct a unix pipeline to do the following:
Extract a fields or characters.
Search based on a pattern.
Count the number of lines.
Search a directory based on a pattern or file attribute.
List the processes on the current machine.
How do you use list comprehensions?
How do you use generator expressions?
How do you split and join strings?
Given a list
of integers called numbers
, produce a new list
called
fives
which consist only of the multiples of 5
by using filter
and
lambda
.
Then, do the same thing using list comprehensions.
Why is C considered a systems programming language?
What is the compiler pipeline?
What exactly happens when you compile a program (ie. describe the compiler pipeline)?
What is the difference between a dynamic executable and a static executable?
What is the difference between a shared library and a static library?
How do you write a Makefile that utilizes rules and variables for a program that consists of multiple files?
What exactly is a pointer? array? string? How are they related?
What does it mean to dereference a pointer?
How do we get the address of a variable?
What are multiple ways to access an element of an array or string?
How much memory is allocated when we declare an int
, float
,
double
, char
, array, string, or pointer?
What is the difference between little-endian and big-endian?
When we declare a variable, where is the data allocated (stack, heap, data, code)?
Review Reading 09: data representation, memory allocation, and memory errors.
What is singly-linked list?
How would we insert an entry into a linked list?
How would we search for an entry in a linked list?
How would we remove an entry in a linked list?
What are the time and space complexities of the insert, search, and remove operations?
What is hash table?
What is a collision?
How does separate chaining handle a collision?
How does load factor impact the performance of a hash table?
What are the time and space complexities of the insert, search, and remove operations?
Review Cadence on how to build basic data structures such as a linked list and hash table.
How do we dynamically allocate memory? How do we deallocate that memory?
When should we allocate on the stack? heap? data? What are the advantages and disadvantages of utilizing each memory segment?
How do we detect and fix memory errors such as: segmentation faults, invalid reads, uninitialized memory, and memory leaks?
An anagram is a word formed by rearranging the letters of another word. For instance, cinema is an anagram of iceman. The following function determines if the two given strings are anagrams:
bool is_anagram(const char *s1, const char *s2) { int max = 0; for (const char *c = s1; c; c++) { if (*c > max) max = *c; } for (const char *c = s2; c; c++) { if (*c > max) max = *c; } int *counts1 = malloc(max * sizeof(int)), *counts2 = malloc(max * sizeof(int)); for (const char *c = s1; c; c++) { counts1[(int)*c]++; } for (const char *c = s2; c; c++) { counts2[(int)*c]++; } for (int i = 0; i <= max; i++) if (counts1[i] != counts2[i]) { return false; } free(counts1); free(counts2); return true; }
This function has the following memory errors: segmentation fault, invalid read, uninitialized memory, and memory leak. Briefly describe how you would fix these errors.
What exactly are system calls?
What is the difference between user mode and kernel mode?
What happens when an application performs a system call?
What are some reasons why system calls related to files, processes, and networking would fail?
How do we check these failures?
How do we get the error message related to these failures?
What exactly is a file descriptor and what system calls can we do with one?
How do we get the inode information for a file?
How would you use system calls in C to accomplish the following tasks:
Display the contents of a file?
Copy the contents of a file?
Check if a file is a regular file, directory, or symlink?
Check if a file is a readable, writable, or executable?
Check the size of the file?
Check the last modification time?
List the contents of a directory? in sorted order?
Review Reading 10: using system calls to manipulate files and directories.
What is a process?
What attributes or components does it have?
What system calls can you do with them?
What happens during the life cycle of a typical process?
How do we prevent a fork bomb?
How do we prevent zombies?
Why would we want to prevent these situations?
What is a signal?
Draw a diagram of the typical life cycle of a process.
Review Reading 11: using fork, exec, and wait.
What is networking?
What is an IP address and what is a domain name?
What is a network port?
What is a URL and what are its components?
What is HTTP?
What system calls does a typical HTTP client perform? What messages does it send and receive?
What system calls does a typical HTTP server perform? What messages does it send and receive?
Modify echo_client_refactored.c to implement a port scanner (ie. nc
-z
) or a HTTP client (ie. curl
).
Review Reading 12: using sockets to connect to another machine.