Processes and threads Flashcards
Processes
A Program has one or more points of execution
Each Execution is called a thread of execution
Thread
The set of threads comprise a process
Each thread contains:
An Instruction Pointer, a register with next instruction
A stack for temporary data (e.g. return addresses, parameters)
A data area for data declared globally and statically
A Process/ Thread is active, while program is not
How To Run A Program
The executable code is loaded onto memory
Space is allocated to the process
Registers are updated
Control (of execution) goes to the process
Process runs one instruction at a time, in a cycle:
Fetch the instruction from memory
Decode the instruction,
Update the IP
Execute the instruction
Process Management - Multitasking
Multi-tasking (concurrency)
Allows a single CPU to be shared between several independent processes
Computer appears to be running multiple applications
But a CPU only deals with one process at a time
OS switches different processes into CPU many times a second
Process Management - Definitions
Multi-tasking - Allows more than one program to run correctly
Multi-user - Allows two or more users to run programs at the same time
Multi-processing - Supports running a program on more than one CPU. Processes run in parallel
Real Time - Responds to input instantly. Used for mission critical applications e.g. spacecraft telemetry
CPU Scheduling
FIFO - First In, First Out -
Processes the jobs in order of arrival in the ready queue
Processor 1 goes into CPU Then into terminated then number 2 moves up the queue into the CPU once number 1 finished
Then when number 2 is finished number 3 does the same thing
Round Robin
Select Jobs from queue on FIFO basis, But only allow limited amount of time of the CPU
If the jobs exceeds this limit, it is interrupted and returned to the “ready” queue and the next job given CPU time
SJF - Shortest Job First
Processes the job with the shortest estimated run time first. New short job can “jump” the queue
May need to use a priority system to ensure that large jobs do get run
Process Management - States
There are 5 process states:
New - the process is being created
Running - the process has CPU time and code is being executed
Waiting - the process is waiting for an event, e.g. access to I/O, user input
Ready - the process waiting for CPU time
Terminated - the process has finished execution
A new process has been created and it has been admitted into the ready queue
Its provided access to the CPU so it is running
Then it may take too long it isn’t able to carry out the full tasks so it moves into waiting
Then when input or output devices become available to moved back to the ready queue
Then gives CPU time so its running again
Then this time it completed its entire tasks so then the process is terminated
With a single CPU, there is only one process running at any one time but there may be multiple processes ready or waiting
I/O
Batch Jobs
Where programs that run without user interaction
User Jobs
Programs that may have user interaction
CPU-I/O burst cycle
Characteristic process execution, which alternates, between CPU and I/O activity
CPU times are generally much shorter than I/O times
Process Management - Interrupts
Special Signals sent by hardware or software to the CPU when it needs immediate attention
The signal alerts the processor CPU to a high priority process requiring the interruption of the current working process
OS may ignore some interrupts to finish current job
Although there are some interrupts that are so important that they can’t be ignored( e.g. memory errors, disk corruption)
Single-CPU OS:
One Process executing at any one time
Suspended for urgent interrupts
Pre-emptive Scheduling:
An interrupt causes currently running process to give up the CPU and he replaced by another process
Priority Based Scheduling
Each job in the ready pool has an associated priority value
The scheduler favour jobs with higher priority values
External priority values:
Imposed on the system from outside
Reflect external preferences for users or tasks
Example: Unix nice system call to lower priority of a task (also found in Unix-like operating systems such as Linux)
Memory Management - Types
Three Types of memory: High-speed cache
Small fast memory holding data recently accessed by the CPU
Designed to speed up subsequent access to the same data
RAM - Random Access Memory
This the main physical memory
Order of access to different locations does not affect the speed of access
Virtual Memory
Hard Disk space used for storing areas of RAM which have not recently been used