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:
A. Scripting
Commands (multiple choice, fill-in-the-blank).
Shell Scripting (multiple choice, fill-in-the-blank).
Python Scripting (multiple choice).
Unix Philosophy (multiple choice).
B. C
Compiling and Building (multiple choice, fill-in-the-blank).
Pointers, Arrays, Strings (multiple choice, fill-in-the-blank).
Memory Allocation/Management (multiple choice, fill-in-the-blank).
Command-Line Arguments/Bitsets: (multiple choice, fill-in-the-blank).
C. System Calls
File System (multiple choice, fill-in-the-blank).
I/O (multiple choice, fill-in-the-blank).
Processes (multiple choice, fill-in-the-blank).
Networking (multiple choice, fill-in-the-blank).
D. Programming
Write a Python script that processes data.
Write a C program that uses system calls.
Parts A, B, and C are to be done first on paper. Once that portion is completed and submitted, you will do part D on your own computer and submit code to your assignments repository.
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 third of the class, as detailed below.
This check list is meant to be representative, rather than exhaustive (ie. there may be questions that show up on the exam that are not shown below).
Exam 03 will take place on Monday, May 6 from 8:00 AM - 10:00 AM in 102 DeBartolo Hall.
As noted above, the first portion of the exam with be on paper, while the remaining component with require coding and submitting work to your assignments repository on GitHub.
During the paper portion of the exam, students will only be allowed to use three cheatsheets. This paper component of the exam must be submitted before students can access the coding section.
For the coding portion, students will use their own computer, and thus are permitted access to any material in their textbooks, notes, assignments, and the Internet.
Although students are allowed to use their computers and the Internet during the exam, students may not communicate with others or solicit answers from others. Nor may they use AI tools such as ChatGPT or Copilot. Students caught sharing solutions or violating any portion of the honor code will receive a zero on the exam.
Furthermore, students are not allowed to consult, copy, or share material from previous sections of this course.
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 happens during I/O redirection?
What is concurrency and what is parallelism?
What makes concurrency challenging?
What are some different types of parallelism?
What are some common examples of these types 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.
Which of the following pipelines counts all the "Permission denied" errors encountered when recursively searching file names under the "/etc" directory?
find /etc > /dev/null | wc -l
find /etc 2>&1 > /dev/null | wc -l
find /etc 2> /dev/null | wc -l
find /etc > /dev/null 2>&1 | wc -l
How do you use list comprehensions?
How do you use generator expressions?
How do you sort data?
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.
Write a program isitdown.py
that uses os.system and curl to check
if a series of websites are down (ie. respond with successful HTTP
requests).
$ ./isitdown.py google.com nd.edu fake.website example.com
google.com UP
nd.edu UP
fake.website DOWN
example.com UP
Then, do the same thing using requests.
You may wish to review Exam 01 and Exam 02, along with previous quizzes assocated with those exams.
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?
Why is it important to specify all the dependencies of a target in a
Makefile
rule?
What is the difference between compiling and linking? What are some common errors that can occur in each phase?
Write a Makefile
for a project that outputs a shared library, a
static library, a dynamic executable, and a static executable.
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?
Given the following code:
int main(int argc, char *argv[]) { // | Label | Address | Value |
int n = 16; // | | 0xF | |
int a[] = {n}; // | n | 0xE | 0x10 |
int *p = a; // | | 0xD | |
return 0; // | | 0xC | |
} // | | 0xB | |
Assuming a 16-bit machine where each integer is 2 bytes, each character is 1 byte, and each pointer is 2 bytes, fill in the stack frame to the right by recording the location of the variables above and their values at the appropriate addresses.
The variable n
is done for you; you need to add p
and a
to the
stack frame.
Distinguish between the character 0
and the integer 0
by using
hexadecimal for integers.
How much memory is allocated when we declare an int
, float
,
double
, char
, array, string, or pointer?
When we declare a variable, where is the data allocated (stack, heap, data, code)?
Given the following C program:
typedef struct
{
char key;
int value;
} Pair;
int main(int argc, char* argv[])
{
char c = 'k';
int v = 2;
Pair p0 = {c, v};
Pair *p1 = malloc(sizeof(Pair));
Pair *p2 = calloc(v, sizeof(Pair));
Pair **p3 = calloc(v, sizeof(Pair *));
return 0;
}
How much memory was allocated on the stack, heap, and data for each
of the variables in the main
function?
Review Reading 10: Memory Management.
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?
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?
Given the following C program:
typedef struct Node
{
int value;
struct Node *next;
} Node;
typedef struct {
Node *head;
} List;
void list_fprint(List *l, FILE *stream)
{
for (Node *c = l->head; c; c = c->next)
fprintf(stream, "%d\n", c->value);
}
bool list_remove(List *l, int v)
{
// TODO
}
int main(int argc, char *argv[])
{
List l;
char buffer[BUFSIZ];
while (fgets(buffer, BUFSIZ, stdin))
{
Node *next = calloc(1, sizeof(Node));
next->value = atoi(buffer);
next->next = l.head;
l.head = next;
}
list_fprint(&l, stdout);
list_remove(&l, 42);
return 0;
}
Given the linked list code above, implement the list_remove
function
which removes all nodes that contain the specified value. Return
whether or not any node was removed.
How do you process command line arguments in C (using while
or
for
loop)?
How do you implement a bitset in C that support insertion, removal, and searching?
What exactly are system calls?
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?
Review Reading 11: 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?
Given the following C code:
/* forking.c */
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int main(int argc, char *argv[])
{
int status = 0;
for (int i = 1; i < argc; i++)
{
pid_t pid = fork();
if (pid < 0)
{
return EXIT_FAILURE;
}
if (pid == 0)
{
execlp(argv[i], "forkit", NULL);
}
}
for (int i = 1; i < argc; i++)
{
int child_status;
while (wait(&child_status) < 0)
{
status += child_status;
}
}
return status;
}
Which of the following statements are true (select all that apply)?
execlp
always succeeds.execlp
always fails.execlp
may succeed depending on the arguments.main
will always return with success.main
will always return with failure.main
will may return with success depending on the arguments.Review Reading 12: 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 http_client.c to implement a port scanner (ie. nc -z
).
Review Reading 13: using sockets to connect to another machine.