Lecture 03 Flashcards
What are the four possible status codes for a process?
O, S, R, and Z
What does the process status code ‘O’ mean?
The process is running on a processor.
What does the process status code ‘S’ mean?
The process is sleeping.
It is waiting for an event complete.
What does the process status code ‘R’ mean?
Runnable.
The process is on run queue.
What does the process status code ‘Z’ mean?
The process is in Zombie State.
It has terminated and the parent is not waiting.
What is a process?
A program in execution.
What function is used to get a processes id?
getpid()
What function is used to create a new process?
fork()
Parent and child processes execute:
A - In Parallel
B - In Series
In parallel.
What is the return value of fork for the parent process?
The new child’s process id.
What is the return value of fork for the child process?
0
What function is used to get the process id of a process’ parent?
getppid
What happens if a parent terminates before its child process?
The child is assigned the ‘init’ process as its parent.
What process id does the ‘init’ process have?
1.
What happens to the memory space of a process (in theory), after a fork?
Its entire memory space is copied to the new process so that they both have an independent copy.
What function is used to wait on a child process completing?
wait()
What does the wait() function do?
Blocks until a child terminates.
When will wait return immediately?
When there are no children or a child has already terminated.
What happens when a child process terminates but has not been waited on by the parent?
It becomes a zombie state.
When a process enters zombie state, what happens to its memory and resources?
They are de-allocated.
What does it mean for a Zombie process to be ‘reaped’?
Its parent process has waited on it, so it is now cleared from the ‘process table’.
What does the ‘exec’ function do?
Replaces the current program of a process with a new program.
What function replaces the current program of a process with a new program?
exec()
Using exec to open a new program, what happens to the text, stack, heap, and data of the current process?
They are overwritten.
Using exec to open a new program, what happens to the open file descriptors of the current process?
They are retained.
What is the difference between exit() and _exit()?
exit flushes the standard buffers and calls registered clean-up function.
_exit just returns immediately to the OS without any clean-up.
What function is used to register functions to be called on process exit?
atexit()
What is the function prototype for atexit?
int atexit(void (*function)(void));
What does the atexit function do?
Registers a function as an exit-handler. It will be called when the process exits.
What are Environment Variables stored as?
Key/value pairs.
What is the function prototype for getenv?
char* getenv(const char *name);
What function is used to get the value of a specific environment variable?
getenv()
What command shows the shell environment?
set
What is the difference between static and shared libraries, memory-wise?
With static libraries, each program has a copy of the library in memory.
With shared libraries, each program shares one copy of the memory - it’s only kept in memory once.
When a static library is changed, programs using it must be ___?
Re-linked.
What are the five stages of the static library example?
Page 33
- Declare functions
- Define functions
- Compile, but don’t link
- Create archive
- Link library with application code.
What are the five stages of the shared library example?
Page 36
- Declare and define library functions as before
- Compile (but do not link)
- Create shared library archive
- Link library with application code
- Setup the library search path