You are on page 1of 13

Operating System Concepts

The Process
Chapter 4

Fakhar Lodhi
Some History
Batch Processing - Just Libraries
• One program ran at a time, controlled by a human operator
• Job queue
• OS didn’t do too much.
• Just a set of libraries of commonly-used functions;
• e.g. low-level I/O handling code, the “OS” would provide such APIs, and thus make
life easier for the developer.
• No interaction – batch processing
Some History
System Calls and Protection
• Realization that OS was different from user program
• control of devices and thus should be treated differently than normal application
code
• User-mode vs supervisor-mode
• System call
• OS as a separate program
• add a special pair of hardware instructions and hardware state to make the
transition into the OS a more formal, controlled process
• raising the hardware privilege level
Some History
Multiprogramming
• Desire to make better use of machine resources
• OS would load a number of jobs into memory and switch rapidly between
them, thus improving CPU utilization
• Slow I/O devices
• program has to wait on the CPU while its I/O was being serviced
• was a waste of CPU time
• Why not switch to another job and run it for a while
• Issues of memory protection and concurrency
The Process – a running program
• A typical system may be seemingly running tens or even hundreds of
processes at the same time

How to provide the illusion that each


process has its own processor?
CPU Virtualization
• How to provide the illusion that each process has its own processor?

Time sharing!
Machine State
• Memory - Address Space
• the memory that the process can address is part of the process
• where the instruction and data belonging to the process resides
• Registers
• General purpose registers – data that is being processed
• Program Counter (PC)
• Stack Pointer
• Persistence I/O – list of open files

At any given time, what parts of the machine are important


to the execution of this program?
Process API
• Create:
• An operating system must include some method to create new processes
• Destroy:
• provide an interface to destroy processes forcefully
• Wait:
• Sometimes it is useful to wait for a process to stop running
• Miscellaneous Control:
• e.g. suspend and resume
• Status:
• get some status information about a process, such as how long it has run for, or what
state it is in.
From Program to
Process
1. Load code and static data into the
address space of the process
• eager vs lazy loading
2. Allocate memory for
• run-time stack
• program’s heap
3. Do some other initialization – I/O setup
4. Start the program running at the entry
point
• the OS transfers control of the CPU to the
newly-created process
• Running:
Process States • In the running state, a process is running on a
processor.
• This means it is executing instructions.
• Ready:
• In the ready state, a process is ready to run
but for some reason the OS has chosen not to
run it at this given moment.
• Blocked:
• In the blocked state, a process has performed
some kind of operation that makes it not
ready to run until some other event takes
place.
• A common example: when a process initiates
an I/O request to a disk, it becomes blocked
and thus some other process can use the
processor.
Process States
• Ready to running - means the process
has been scheduled
• running to ready - means the process
has been descheduled
• Once a process has become blocked
(e.g., by initiating an I/O operation),
the OS will keep it as such until some
event occurs (e.g., I/O completion)
• at that point, the process moves to the
ready state again
Process States
Time Process0 Process1 Notes
1 Running - Process0 created
created
2 Running Ready Process1 is created
3 Running Ready Process0 initiates I/O
4 Blocked Running Process0 is blocked, Process1 gets CPU
5 Blocked Running
6 Blocked Running
7 Ready Running I/O done
8 Ready Running Process1 done
9 Running -
10 Running - Process0 done
Process States
Final
Initial Ready Running aka
Zombie

Blocked

You might also like