Lecture 4 Flashcards
What’s special about Fork()’s return?
It returns twice (0 to child, PID of new process to parent)
execlp() command ____ current program
Overwrites
What is exit()
Process executes last statement and asks OS to delete it
What happens when a process terminates?
Process’ resources are de-allocated by OS and outputs data from child to parent via wait()
What is abort()
Parent terminating execution of child processes
Why is abort() called?
- Child has exceeded allocated resources
- Task assigned to child is no longer required
- If parent is exiting, some OS do not allow children to continue (causes cascade termination)
Zombie Process
Process terminated but parent hasn’t called wait() yet
Where is the return value of a zombie process kept?
Held in memory
Orphan Process
Process is running but parent exited without calling wait()
What is adoption?
An orphan process being assigned a new parent (init process in Linux)
Thread
A sequence of instructions in a function that a CPU can execute as a unit
Thread is comprised of (from OS perspective):
- Program Counter
- Register Set
- Stack
Process is composed of…
…one or more threads
Threads belonging to the same process share:
- Code section
- Data section
- OS resources such as open files and signals
Why multithreading?
- Responsiveness
- Resource Sharing
- Economy
- Stability
Threads can be created and managed at two levels:
User-level threads and kernel-level threads
User Level Thread
- All Data Structures are maintained in user level
- All thread operations are performed in user level
- Kernel knows nothing about user-level threads
- Provided by user-level libraries
Kernel Level Thread
- All data structures maintained in kernel space
- All thread operations need system calls to perform them
- Provided by the OS
Mapping from user-level to kernel-level threads can be:
- Many-to-many
- One-to-one
- Many-to-one
Many-to-one
- Many user-level threads mapped to one kernel-level thread
- Thread management is done in user level
Pros and cons of many-to-one
- Pro: Managing user-level threads is faster (no system calls, no switching to kernel mode)
- Con: One thread blocks, the entire process blocks; cannot use multiprocessors
One-to-one
Each user-level thread mapped to one kernel-level thread
Pros and cons of one-to-one
- Pro: Can use multiprocessors; one thread blocks, the others can run
- Con: Thread management overhead; creating too many kernel threads may degrade performance since they consume OS resources