Lecture 03 Flashcards

1
Q

What are the four possible status codes for a process?

A

O, S, R, and Z

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the process status code ‘O’ mean?

A

The process is running on a processor.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the process status code ‘S’ mean?

A

The process is sleeping.

It is waiting for an event complete.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the process status code ‘R’ mean?

A

Runnable.

The process is on run queue.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does the process status code ‘Z’ mean?

A

The process is in Zombie State.

It has terminated and the parent is not waiting.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a process?

A

A program in execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What function is used to get a processes id?

A

getpid()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What function is used to create a new process?

A

fork()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Parent and child processes execute:
A - In Parallel
B - In Series

A

In parallel.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the return value of fork for the parent process?

A

The new child’s process id.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the return value of fork for the child process?

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What function is used to get the process id of a process’ parent?

A

getppid

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What happens if a parent terminates before its child process?

A

The child is assigned the ‘init’ process as its parent.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What process id does the ‘init’ process have?

A

1.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What happens to the memory space of a process (in theory), after a fork?

A

Its entire memory space is copied to the new process so that they both have an independent copy.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What function is used to wait on a child process completing?

A

wait()

17
Q

What does the wait() function do?

A

Blocks until a child terminates.

18
Q

When will wait return immediately?

A

When there are no children or a child has already terminated.

19
Q

What happens when a child process terminates but has not been waited on by the parent?

A

It becomes a zombie state.

20
Q

When a process enters zombie state, what happens to its memory and resources?

A

They are de-allocated.

21
Q

What does it mean for a Zombie process to be ‘reaped’?

A

Its parent process has waited on it, so it is now cleared from the ‘process table’.

22
Q

What does the ‘exec’ function do?

A

Replaces the current program of a process with a new program.

23
Q

What function replaces the current program of a process with a new program?

A

exec()

24
Q

Using exec to open a new program, what happens to the text, stack, heap, and data of the current process?

A

They are overwritten.

25
Q

Using exec to open a new program, what happens to the open file descriptors of the current process?

A

They are retained.

26
Q

What is the difference between exit() and _exit()?

A

exit flushes the standard buffers and calls registered clean-up function.
_exit just returns immediately to the OS without any clean-up.

27
Q

What function is used to register functions to be called on process exit?

A

atexit()

28
Q

What is the function prototype for atexit?

A

int atexit(void (*function)(void));

29
Q

What does the atexit function do?

A

Registers a function as an exit-handler. It will be called when the process exits.

30
Q

What are Environment Variables stored as?

A

Key/value pairs.

31
Q

What is the function prototype for getenv?

A

char* getenv(const char *name);

32
Q

What function is used to get the value of a specific environment variable?

A

getenv()

33
Q

What command shows the shell environment?

A

set

34
Q

What is the difference between static and shared libraries, memory-wise?

A

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.

35
Q

When a static library is changed, programs using it must be ___?

A

Re-linked.

36
Q

What are the five stages of the static library example?

Page 33

A
  • Declare functions
  • Define functions
  • Compile, but don’t link
  • Create archive
  • Link library with application code.
37
Q

What are the five stages of the shared library example?

Page 36

A
  • 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