Fork and pipe Flashcards
(48 cards)
What is a process?
A running instance of a program
What is the benefits of using multiple processes?
(1) Do multiple tasks at once
(2) If one process fails, others are still running
(3) Make use of existing processes
What are the numbers corresponding to stdin, stdout, stderr?
stdin 0, stdout 1, stderr 2
Which of stdin, stdout, stderr goes to the display?
stdout and stderr
Where does the input of stdin come from?
Keyboard
Describe the virtual memory layout of a process from top to bottom.
OS kernel space, stack (which grows down), empty space, heap (which grow up), bss, data, text
What is BSS in the virtual memory layout?
BSS is uninitialized data.
When a process is being created, what is this state called?
The process is idle
When a process is waiting for resources, what is this state called?
The process is waiting.
When a process ended and is waiting to be collect, what is this state called?
The process is a zombie.
Describe the life cycle of a process.
Idle -> Ready -> Run -> Zombie
Run -> Wait (for resources) -> Ready ->
Run -> Ready
What is a command to check the current running processes?
ps -f
What is a system call?
A system call is a way for a program (in the user space) to request services from the OS (in kernel space). Some services including requesting OS managed resources like files, memories, devices.
How does syscalls work depending on the programming language and the OS?
syscalls work the same in every programming language, but it is dependent on OS
What is the difference between a normal function call and a syscall?
A syscall looks like a function call but it transfers control to the OS
Describe what fork() does.
fork() creates a copy of the current process and starts it as a child.
Describe what execv() and execl() does.
It takes an executable as the input, which completely replaces the current process (so in memory, the new code takes over). The executable starts running and the only way to terminate is through termination of the program. (Since the original process is replaced, this new process does not return to the calling program).
If execv() or execl() fails, it returns -1 and the main program continues to run.
What does wait() and waitpid() do?
These system calls make a parent process wait for a child process to terminate. This allows the parent to manage child processes, retrieve their exit status, and properly cleanup resources. This also prevents creating zombie processes.
wait() waits until one child terminates.
waitpid() allows the parent to specify which child to wait for.
These two syscalls both return the terminated child’s PID.
What does kill() do?
Send a signal (SIGTERM, SIGKILL, SIGINT) to another process
Does each process have a parent?
Yes.
What is a parent process’ id?
Ppid (Parent process identifier)
How to get a process and its parent’s id?
getpid(), getppid()
What is the reason to kill a process?
When a process is frozen or non-responding and it takes up too much resources.
What does fork() return?
In the parent, fork() returns the process id of the newly created child.
In the child, fork() returns 0 to indicate that it is a child process.