This is a general outline of the key concepts (arranged by topic) that you should know for the Exam 03.

Format

The exam will have the following format:

  1. Code Snippets: Evaluate or write Shell commands or Python code to perform certain tasks. (6 Points)

  2. Short Answers: Briefly answer questions about:

  3. 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).

Comprehensive

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.


Scripting

  1. What is Unix?

  2. What are the principles of functional programming?

  3. What is concurrency and what is parallelism?


Shell

How do you construct a unix pipeline to do the following:

  1. Extract a fields or characters.

  2. Search based on a pattern.

  3. Count the number of lines.

  4. Search a directory based on a pattern or file attribute.

  5. List the processes on the current machine.


Python

  1. How do you use map, filter, and lambda?

  2. How do you use list comprehensions?

  3. How do you use generator expressions?

  4. How do you split and join strings?

Sample Question

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.


C

  1. Why bother with C? Why not just Python or C++?

  2. Why is C considered a systems programming language?

  3. What is C's relationship to Unix?


Compiling and Makefiles

  1. 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?

  2. How do you write a Makefile that utilizes rules and variables for a program that consists of multiple files?


Pointers, Arrays, Strings

  1. What exactly is a pointer? array? string? How are they related?

  2. What does it mean to dereference a pointer?

  3. How do we get the address of a variable?

  4. What are multiple ways to access an element of an array or string?


Data Representation

  1. What is the difference between a struct and a union?

  2. How much memory is allocated when we declare an int, float, double, char, array, string, or pointer?

  3. What is the difference between little-endian and big-endian?

  4. When we declare a variable, where is the data allocated (stack, heap, data, code)?

Big Brain

Review Reading 09: data representation, memory allocation, and memory errors.


Data Structures

  1. 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?

  2. What is hash table?

Big Brain

Review Cadence on how to build basic data structures such as a linked list and hash table.

Memory

  1. How do we dynamically allocate memory? How do we deallocate that memory?

  2. When should we allocate on the stack? heap? data? What are the advantages and disadvantages of utilizing each memory segment?

  3. How do we detect and fix memory errors such as: segmentation faults, invalid reads, uninitialized memory, and memory leaks?

Sample Question

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.


System Calls

  1. What exactly are system calls?

  2. 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?


Files

  1. What is the difference between open and fopen?

  2. What exactly is a file descriptor and what system calls can we do with one?

  3. How do we get the inode information for a file?

Sample Question

How would you use system calls in C to accomplish the following tasks:

Big Brain

Review Reading 10: using system calls to manipulate files and directories.


Processes

  1. What is a process?

    • What attributes or components does it have?

    • What system calls can you do with them?

  2. What happens during the life cycle of a typical process?

    • After a fork, how does a process determine if they are the child or parent?

    • After a fork, who executes first: parent or child?

    • What happens when a process performs exec?

    • Why is it necessary to perform a wait?

    • What is the purpose of exit?

  3. How do we prevent a fork bomb?

    • How do we prevent zombies?

    • Why would we want to prevent these situations?

  4. What is a signal?

Sample Question

Draw a diagram of the typical life cycle of a process.

Big Brain

Review Reading 11: using fork, exec, and wait.


Networking

  1. What is networking?

  2. What is a URL and what are its components?

  3. How are sockets like files? How are they different?

  4. 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?

Sample Question

Modify echo_client_refactored.c to implement a port scanner (ie. nc -z) or a HTTP client (ie. curl).

Big Brain

Review Reading 12: using sockets to connect to another machine.