Processes, LDEs & Threads Flashcards
Time sharing
Running one program for a little while, then running another one, and so forth
What illusion does time sharing promote?
The illusion that many virtual CPUs exist
What is the consequence of time sharing promoting the illusion that many virtual CPUs exist?
Each program believes that it is using the CPU alone
Mechanisms
Low-level methods/protocols that implement a needed piece of functionality
Policies
Algorithms for making some kind of decision within the OS
Program/Executable file
A static entity stored on disk
Process
A running program
A program becomes a process when…
it is selected to execute and loaded into memory
Loading
Takes on-disk program and reads it into the address space of process
How does the OS run a program?
Loads code and any static data into memory
Allocates memory for the program’s run time stack
Initializes the stack with arguments
Allocates memory for the program’s heap
Initialization tasks + main()
What does a process consist of?
Address space
Code
Stack
Registers
Data
Heap
What does the address space that a process consists of contain?
Memory that the process can address
What does the stack that a process consists of contain?
Temporary data
What do the registers that a process consists of contain?
Program Counter, general purpose, stack pointer and frame pointer
Program Counter (PC)
Tells us which instruction the program will execute next
Stack pointer and frame pointer
Manage the stack for function parameters, local variables and return addresses
What does the data that a process consists of contain?
Global variables
What does the heap that a process consists of contain?
Dynamically allocated structures
How does the OS track the state of each process?
By keeping a process list
Register context
The contents of the registers of a stopped process
Where is each entry in a process list found?
Process Control Block (PCB)
What are the different process states?
INITIAL
READY
RUNNING
BLOCKED
ZOMBIE
INITIAL
The state a process is in when it’s being created
READY
The state a process is in when it’s ready to run and pending for running
RUNNING
The state a process is in when it’s being executed by the OS.
BLOCKED
The state a process is in when it’s suspended due to other events
ZOMBIE/FINAL
The state a process is in when it’s completed execution but still has an entry in the system
SCHEDULED
A process that’s moved from READY to RUNNING
DESCHEDULED
A process that’s moved from RUNNING to READY
What do process APIs do?
Manipulate processes
CREATE
When a process API creates new processes
WAIT
When a process API waits for a process to stop running
DESTROY
When a process API destroys the processes forcefully
STATUS
When a process API obtains information about a process
OTHERS
When a process API suspends/resumes a process
What does process creation rely on in a Unix-like OS?
fork() and exec()
fork()
Creates a new process and clones its parent process
exec()
Allows a child to break free from its similarity to its parent and execute an entirely new program
What does the following return value from a fork() system call indicate: non-zero PID
Return value of the parent process
What does the following return value from a fork() system call indicate: zero
Return value of the new child process
What does the following return value from a fork() system call indicate: - 1
An error/failure occurred when creating a new process
What are the two differences between a parent and a child process?
PID and memory addresses
wait()
Allows a parent to wait for its child to complete execution
What does the shell consist of?
fork() + wait() + exec()
Why do we have a process API?
- Maintains the shell structure
- Makes IO redirection and pipe possible
Pipe
Communication method between two processes
Why do we have processes?
To build applications using communication process; makes it possible for us to write applications that fully utilize many cores
Limited Direct Execution (LDE)
Kernel initializes the trap table & the CPU remembers its location for subsequent use
Kernel set-up before using a return-from-trap instruction to start the execution of a process
Kernel mode
The mode the OS runs in. In this mode, code that runs can do what it likes, including privileged operations.
What does the system call allow the kernel to do?
Carefully expose certain key pieces of functionality to user programs
Trap instruction
Simultaneously jumps into the kernel and raises the privilege level to kernel mode
Return-from-trap instruction
Returns into the calling user program while simultaneously reducing the privilege level back to user mode
Timer interrupt
A timer device that’s programmed to raise an interrupt every so many ms.
Context switch
When the OS switches processes
What does the disable interrupts mechanism in LDE ensure?
Concurrency; when one interrupt is being handled, no other one while be delivered to the CPU
What does the locking scheme mechanism in LDE enable?
Concurrency; multiple activities can be on-going within the kernel at the same time
Why do we use threads?
To enable inter-process communication
What do threads share?
The same address space
What do multiple threads within a process share?
Process ID
Address space
Open files
Current working directory
Each thread has its own:
Thread ID
Set of registers
Stack for local variables & return addresses
What is a process in a OS?
A running program with an address space
What do we use process APIs for?
Creating and managing processes
On Unix-like systems what to we use fork() to do?
Duplicate a process
On Unix-like systems what do we use exec() to do?
Replace a command
What are threads?
Lightweight processes