5. Process API Flashcards
What are the system calls to create a new process?
fork() and exec()
What does fork() do?
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.
What does wait() do?
It waits for a completion of a given process.
What does exec() do?
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.
Why there was a need to separate fork() and exec()? Why not create a process right away?
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)
Which system call is used to send signals to processes?
kill()
What program needs to use to react to signals sent to it by, for example, kill()?
It should use signal() interface to catch various signals and pass them to functions that handle them further
What are main exec() calls, what is difference between them?
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