Lecture 4: Processes 1 Flashcards
Role of the OS:
- Resource Abstraction
- Resource Sharing
Supported in the these ways:
- Process and thread management (resource: CPU)
- Memory management (resource: Memory)
- File management (resource: Secondary Storage)
- I/O system management (resource: Devices)
- Protection system (resource: All)
- Command-interpreter system (resource: All)
Shell (or Command-Line-Interpreter)
- A shell is a job control system which allows the programmer to create and manage a set of programs to do some task.
- it is a program that reads and interprets control statements.
- The “visible face” of an OS (sometimes with GUI (e.g.: Windows)
® Process creation and management ® I/O handling ® Secondary storage management ® Main memory management ® File system access ® Protection
Control Statements of the Shell
User-driven commands to the OS (vs. event-driven commands such as interrupts)
Process
-program in execution
How Is a Process an Abstraction of the CPU?
- Gives an illusion of a uniprogramming environment
- Every process acts as though it has exclusive access to the CPU
In Reality: Multiprogramming
- CPU is time-sliced:
processes take turns using the CPU - Memory is space-sliced:
processes get partitions
Threads
- Lightweight process (no isolation)
- Abstraction only of CPU
- One process can have many threads (multithreading), all share the same memory
Difference between threads and processes
- Threads: mostly cooperative. Processes: mostly independent –a thread communication is inexpensive (via shared memory)
- a e.g., a user can type characters and have the speller running - Threads more appropriate for certain applications
What makes up a process?
- Code section (text segment)
- Data section (data segment)
- Stack (stack segment)
- Registers (including Program Counter)
Program vs Process
- Program is a passive entity
- an executable stored in disk
Process is a dynamic entity
-a program becomes a process when it is loaded into memory
Process Control Block (PCB)
Processes Represented In Memory with Current “State”
Context Switch
- process with access to CPU switched out (state copied to PCB)
- another ready process switched in (state copied from PCB)
Process Scheduling: Multiprogramming Goal
- maximize CPU utilization
- have some process running (using the CPU) all time
Process Scheduling: Time –sharing Goal
- users can interact with their running programs
- switch CPU among processes frequently enough
Process Scheduler
it selects the
process for program execution on the CPU
Job Queue
Contains all processes in system
Ready Queue
It includes processes that are residing in main memory and are ready to execute
Device Queues (Waiting) Queue Headers
It includes processes waiting for an I/O device
Schedulers
-Select which processes to allocate to CPU
-Submitted processes can be spooled into disk for
later execution
Short term scheduler
- selects one from memory and allocate the CPU to it
- Selects processes from the ready queue
- Will be invoked frequently (every few milliseconds) Þ needs to be fast!!
Long term scheduler
-moves processes from disk to main memory
- Selects which processes should be brought into ready queue
- Controls degree of multiprogramming (# processes in memory)
- Invoked infrequently (e.g.: seconds or minutes), \ can be slow
- Needs to make a careful process mix between I/O vs CPU bound processes
CPU Bound
spends more time doing computations
I/O Bound
spends more time doing I/O
I/O heavy mix
the ready queue will always be empty (no process is ready to use the CPU as they are in the device queue )
CPU heavy mix
CPU contention, devices are unused and system is unbalanced
Medium-Term Scheduler
- Can reduce the degree of multiprogramming by removing processes from memory (swapping) -> reduce CPU contention
- Can be used to improve the process mix or fix overcommitted memory requirements
Process and Memory
- process also serves as an abstraction of memory
- Process has exclusive access to all memory that it can address
- Process has exclusive access to all memory it can reference
- Memory is partitioned amongst processes
- Memory consists of non-contiguous chunks
Process and Memory Exclusivity
-all processes assigned a base register and limit register defining its address space (e.g.: 10,000 – 12,000 has base register = 10,000 and limit register = 2,000)
- base, limit registers are like status registers (process can’t touch )
- all addressing translated accordingly
Virtual Memory
®
- (P’s addr space) can be larger than physical memory process P
Solution is “Virtual memory”
Idea: Some of process’ address space not in memory but on disk
-transparent to process (will see again later in course)
Memory Mapped I/O
-Reserve addresses in address space to refer to device controller registers (e.g.: video controller, or disk)
-+ I/O registers are part of the regular memory address space.
+ uses the same address bus to address both memory and I/O devices
+ CPU instructions used to access the memory are also used for accessing
devices
Segmentation
Store process’ address space as non-contiguous set of “contiguous chunks”