5. Process API Flashcards

1
Q

What are the system calls to create a new process?

A

fork() and exec()

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

What does fork() do?

A

It creates an exact copy of the process that executed this instruction. Copy has its own address space, registers and so on, and this copy starts running from where the fork() left. It also returns a different value from fork() - 0, while parent returns PID of child it forked.

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

What does wait() do?

A

It waits for a completion of a given process.

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

What does exec() do?

A

Given the program and arguments, it loads code and static data from executable and overwrites its current code segment (and static data), the heap, stack and other parts of memory are re-initialized.

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

Why there was a need to separate fork() and exec()? Why not create a process right away?

A

Because it’s essential to how shell works. It allows shell to modify environment of soon-to-run programs, manage them effecitvely and remain running process (i.e it’s not getting replaced by a program)

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

Which system call is used to send signals to processes?

A

kill()

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

What program needs to use to react to signals sent to it by, for example, kill()?

A

It should use signal() interface to catch various signals and pass them to functions that handle them further

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

What are main exec() calls, what is difference between them?

A

execl() - takes individual arguments instead of list, inherits environment, no PATH lookup
execle() - same as execl(), but can be passed an environment
execlp() - takes individual arguemnts, inherits environment, but has PATH lookup
execv() - takes list of arguments instead of individuals, no PATH lookup
execvp() - takes list of arguments instead of individuals, inherits environment, PATH lookup
execvpe() - takes list of arguments, can be passed environment, PATH lookup
execve() - takes list of arguments, can be passed environment, no PATH lookup

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