Test 3 Flashcards
Chapter 4 and 5
What is a Preprocessing Directive
Any code that begins with # #include #define #ifdef - if defined #ifndef - if not defined
What is in a Header File
- constant definitions
- data type definitions
- function prototypes (but not function implementations)
What are 4 Steps of the Compilation Process
- Preprocessing
- Assembly Code Creation
- Machine Code Creation
- Linking
What are 2 Types of Linking
Static Linking: library code copied into executable
PROS: faster execution time
CONS: larger executable size
Dynamic Linking: library code is loaded at runtime
PROS: smaller executable size
CONS: slower execution time
What is a Makefile
a text file that is used by the make command to automatically build executable programs and libraries from source code
Makefiles: how do you declare a variable
- declare at the top of the file
- e.g. OBJ = linkExample1.o linkExample2.o
- use variable with $(OBJ)
Makefiles: how do you clean?
clean:
rm -f *.o *~
What is concurrent computing
a form of computing where several computations are executed at the same time
What are the 3 main types of concurrent computing?
Multithreaded, multiple processors, and distributed systems
What is a distributed system?
a large program that is executed over multiple physical host machines that communicate via internet or intranet
What is a multi-process system?
a system running multiple processes/executables at the same time and they communicate with each other to accomplish a task
What is a multi-threaded system?
a single process with multiple control flows where multiple tasks are performed by the same CPU but they take turn sharing the CPUs resources
Name 3 common issues with concurrent computing
- Shared Resources
- Deadlocks
- Race conditions
In concurrent computing, what is the issue with shared resources? What are 2 methods for accessing shared variables?
Multiple threads or processes will likely need the same resources.
- Mutex
- Semaphore
What is a Mutex?
MUTual EXclusion object
a program object created so multiple threads can take turns using it. only the thread that locked or acquired it can unlock it
What is a Semaphore?
A variable used to control access to a common resource
It is a generalization of a Mutex
A thread waiting on a semaphore can be signalled by a different thread so that it can have access
In concurrent computing, what are deadlocks?
a condition where multiple threads/processes are blocked and all waiting for a condition that will never occur
ALWAYS DUE TO IMPROPER MUTEX/SEMAPHORE HANDLING
In concurrent computing, what are race conditions?
a timing problem in which the correctness of a program depends on one thread reaching a point in control flow before another thread ( the order things get processed is never guaranteed)
What is process management?
allocating resources to processes, enabling processes to share and exchange info, protecting resources of each process from each other, and enabling syncing of processes
What are two ways that process management can occur?
Shell commands (in the command line) System calls (in a program)
Name the 4 main system calls
FORK
EXEC
WAIT
SYSTEM
How does FORK work?
It creates a new process with the current process as the parent of the new process
When using the fork() function as an R-Value, (int i = fork()) the it returns different values in the parent and child processes
In the parent process, Fork returns the PID of the child
In the child process, Fork returns 0
How does EXEC work?
Allows the code to go off and run another program instead of this continuing with this one (and it uses the same process ID)
int execv(const char *path, char *const argv[]); int execvp(const char *file, char *const argv[]); int execl(const char *path, const char *arg, ....more args); int execlp(const char *file, const char *arg, ... more args);
path = full path to the file file = "./fileName" v = arguments as an array l = arguments as a list
How does WAIT work?
wait(): allows us to put a delay in a parent program until ONE of it’s children returns
waitpid(childPID, &status, 0): allows parent to wait until a specific child is returned