Week 4 Flashcards
Processes (42 cards)
What is a process?
A program that is currently executing. Represents a single task the computer is doing
What hardware does the concept of a process help virtualize?
A CPU
What are the elements of a process?
- one or more threads
- an address space containing instructions and runtime data structures
- zero or more open file handles
What are the 3 process execution states?
- Running
- Ready
- Blocked
Scheduling
When a process is moved between running and ready.
What is exec()?
A syscall that starts a new process by TRANSFORMING the current process, which overwrites the current process with a new process.
What happens to any code after execve()?
Any code after execve() will not be run because it has been transformed.
What does exec() return?
It does not return if successful
Returns -1 on failure.
What exactly does exec() do?
- duplicates address space
- overwrite text segment
- reinitialize stack and heap
What is fork()?
a syscall used to CREATE a new process by creating a copy of the current running program. The original process is called the parent and the new process is the child.
How to tell the difference between the child and the parent after using fork()?
Child receives a value of 0.
Parent receives a value of the PID (process ID)
What is non-determistic execution?
For processes with the same PID the CPU scheduler decides which process runs first, and it can vary every time.
What is wait()?
A syscall that blocks the PARENT process until ONE of its children has finished executing.
Allows the OS to release resources associated with the child, which avoids ZOMBIES.
What is the difference between fork() and exec()?
Fork creates a new process by copying the original process.
Exec transforms a process by replacing the current process into a new process.
Example of using fork(), exec(), and wait() to do a command.
- Use fork() to split into 2 programs
- Use exec() on the child so it doesn’t affect the original process
- Use wait() in the parent code.
Example of using fork in code.
if(fork() != 0){
PARENT CODE }
else {
CHILD CODE
}
Difference between program vs process
Program: a sequence of instructions stored in a file
Process: a program that has been loaded into memory for execution
What is the Program counter (PC)
a register that indicates the next instruction to execute.
What is signal()
a system call used to “catch” various signals like SIGINT (interrupts). Signals are used to help the process stop, continue, or terminate
What is superuser?
Sometimes called the root, has permissions to control all processes and kill them.
What is limited direct execution
Runs software directly on the hardware/CPU for high performance, but the OS still tries to maintain control through different tactics.
What does the trap call in the program do?
Raises the privelege level and jumps into the OS.
Where do we place the return from trap instruction?
In the OS.
Where do we resume execution after the trap?
The Hardware.