Week 2-slides (1)
Week 2-slides (1)
Process
• a program in execution
• Needs resources (CPU time, memory, files, and I/O devices)
• Can be allocated during creation or while it is executing
• system is a collection of processes
Difference between Program and
Process
A program by itself is not a process. A program is a passive entity, such
as contents of a file stored on disk, whereas a process is an active
entity, with a program counter specifying the next instruction to
execute and a set of associated resources. Although two processes may
be associated with the same program, they are considered two
separate sequences of execution. E.g. several users may be running
different instances of the mail program, of which the text sections are
equivalent but the data sections vary.
Two Types Of Processes
I/O bound processes: spend more time doing IO than computations,
have many short CPU bursts. Word processors and text editors are good
examples of such processes.
CPU bound processes: spend more time doing computations, few very
long CPU bursts.
Process States
• The state of a process is defined in part by the current activity of that
process.
• New: The process is being created.
• Running: Instructions are being executed.
• Waiting: The process is waiting for some event to occur (such as an
I/O completion or reception of a signal.
• Ready: The process is waiting to be assigned to a processor.
• Terminated: The process has finished execution.
Process Control Block
• Each process is represented in the operating system by a process
control block (PCB) or task control block. A PCB contains many pieces
of information associated with a specific process.
Process state: The state may be new, ready, running, waiting, halted and so on.
Program counter: The counter indicates the address of the next instruction to be
executed for this process.
CPU registers: The registers vary in number and type, depending on the
computer architecture. They include accumulators, index registers, stack pointers
and general-purpose registers, plus any condition code information. Along with
the program counter, this state information must be saved when an interrupt
occurs, to allow the process to be continued correctly afterwards.
CPU Scheduling information: This information includes a process priority,
pointers to scheduling queues, and any other scheduling parameters.
Memory-management information: This information may include such
information such as the value of the base and limit registers, the page tables, or
the segment tables, depending on the memory system used by the operating
system.
Accounting information: This information includes the amount of CPU and real
time used, time limits, account numbers, job or process numbers, and so on.
I/O status information: The information includes the list of I/O devices allocated
to the process, a list of open files, and so on.
Process Scheduling
• The objective of multiprogramming is to have some process running
all the time so as to maximize CPU utilization.
• The objective of time-sharing is to switch the CPU among processors
so frequently that users can interact with each program while it is
running.
• Context switching:
Switching the CPU from one process to another requires saving
of the context of the current process and loading the state of the new
process.
Scheduling Queues
A modern-day computer system maintains many scheduling queues.
Job Queue: As processes enter the system, they are put into a job queue. This queue
consists of all processes in the system.
Ready Queue: The processes that are residing in main memory and are ready and
waiting to execute are kept on a list called the ready queue. This queue is generally
stored as a linked list. A ready-queue header contains pointers to the first and final
PCBs in the list. Each PCB is extended to include a pointer field that points to the
next PCB in the ready queue.
Device Queue: When a process is allocated the CPU, it executes for a while, and
eventually quits, is interrupted or waits for a particular event, such as completion of
an I/O request. In the case of an I/O request, the device may be busy with the I/O
request of some other process, hence the list of processes waiting for a particular I/O
device is called a device queue. Each device has its own device queue.
Queuing diagram of a computer
system
Schedulers
Long term scheduler (or job scheduler) selects which processes should
be brought into the ready queue, from the job pool that is the list of all
jobs in the system.
Short-term scheduler (or CPU scheduler) selects which process should
be executed next and allocates CPU.
• i.e. select a new process for the CPU
Medium-term scheduler: removes processes from memory/reduces the
degree of multiprogramming/swapping
• The process is swapped out, and is later swapped in.
• The area on the disk where swapped out processes are stored is called
the swap space