Advanced Process Management, Memory Layout, and Stack/Heap Flashcards

(40 cards)

1
Q

What command starts a low-priority background process?

A

nice

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

What command changes the priority of a running process?

A

renice

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

How do you keep a process running even after logout?

A

nohup myProgram &

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

What does fork() do?

A

Creates a child process.

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

What does a return value of < 0 from fork() indicate?

A

Fork failed.

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

What does a return value of 0 from fork() indicate?

A

Child process.

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

What does a return value > 0 from fork() indicate?

A

Parent process (value = child’s PID).

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

What do both parent and child processes share?

A

stdout

  • File descriptors
  • Global/static variables (as copies)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does waitpid() do?

A

Wait for a child process to finish.

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

What can waitpid() wait for?

A
  • A specific child (pid)
  • Any child (pid = 0)
  • Return immediately if no child has exited (WNOHANG)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does exec() do?

A

Replaces the current process with a new one.

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

What happens if exec succeeds?

A

Nothing after it runs.

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

What happens if exec fails?

A

Handle the error.

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

What does pipe() do?

A

Facilitates communication between parent and child processes.

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

What are the characteristics of pipes?

A
  • Unbuffered
  • Unidirectional
  • Must be created before fork()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does SIGINT represent?

A

Ctrl+C

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

Is SIGTERM catchable?

18
Q

Is SIGKILL catchable?

19
Q

What are SIGUSR1 and SIGUSR2?

A

Custom user signals.

20
Q

What does SIGSEGV represent?

21
Q

What command is used to send a signal?

A

kill or signal()

22
Q

What tool is used to create a process?

23
Q

What tool is used to replace a process?

24
Q

What tool is used to wait for a process?

25
What tool is used for communication?
pipe()
26
What is the virtual address space in a program?
Each program thinks it has full access to memory, but the OS maps it.
27
What are the three main segments of runtime memory?
* Text/code segment * Stack * Heap
28
What is stored in the code/text segment?
The program’s machine instructions.
29
What is stored in the stack?
Local variables, function calls.
30
What is stored in the heap?
Memory from malloc(), calloc(), etc.
31
How is stack memory used during function calls?
Functions use stack frames to store parameters and local variables.
32
What happens when a function is called?
* Save old frame pointer (fp) * Move stack pointer (sp) * Allocate space for locals * Execute function * Restore previous frame and return
33
How does the stack grow in memory?
Stack grows downward from high → low memory addresses.
34
What registers are used for the frame pointer and stack pointer?
* %rbp: Base pointer * %rsp: Stack pointer
35
What is recursion in relation to stack memory?
Each recursive call pushes a new frame on the stack.
36
What occurs if there are too many recursive calls?
Stack overflow!
37
What is heap memory used for?
Dynamic allocation of memory.
38
What functions are commonly used for dynamic memory allocation?
malloc(), calloc()
39
What must be done with memory allocated on the heap?
Must call free() manually.
40
What is a consequence of not freeing heap memory?
Memory leak!