Lecture 1 and 2 - Processes
Lecture 1 and 2 - Processes
Processes
Process Concept
Process is a program in execution; process
execution must progress in sequential fashion
A process includes:
1. Text Section: a process is more than the
program code. Text files have a program code
which is different than program codes of E-mail
programs
2. Program counter: Represents the current state
of the process
3. Stack: Contains temporary data like method
parameters, return addresses
4. Data section: Contains global variables
Process State
As a process executes, it changes state. This
state is noticed by the program counter.
new: The process is being created
running: Instructions are being executed
Program counter
CPU registers
Memory-management information
Process B
Process C
Process D
Process A Process B Process C Process D
A Computer Engineer is making cake today.
In his kitchen, he has a book- “how to bake
cake”
He also has ingredients like- flour, baking soda,
custard powder, etc.
The book is the program (algorithm)
The computer engineer is the CPU
The ingredients are input data (remember global
and local variables??)
The process is the activity consisting of our
baker reading the book, fetching the ingredient
and baking the cake!
Now, his youngest son came to the kitchen
He alleged to his father that he has been
attacked by cockroaches and they had a bite on
him!
His father stops baking
The computer engineer took the first aid box
and aided his son
The son is the interrupt program
The first aid box is a different program
The injection, medicines in the box are data
need to run the program
And of course, aiding son is more high
prioritized process than baking cakes!
The engineer after aiding his son comes back to
the kitchen and then again bakes cakes!
Process Creation
Three principal reasons for which a process is
created.
1. System initialization
when the OS is booted, several processes are
created. Some of them are foreground
processes, others are background processes.
Background processes designed to deal with
incoming mails sleep. Whenever a mail comes,
they wake.
Processes that stay in background to handle
some activity like email, web pages, printing are
called Daemons.
Process Creation
2. Process created by other process
mostly done by system calls. In network
sharing, one process may collect the stream of
bytes and store them, other maintains the
buffer while introduced by the first one.
Process Creation
3. Process created by a user request
Whatever you click and do on Windows
platform, with every single click, there is a
possibility to create a new thread!!
Process Creation
In UNIX, there is only one system call to create new
process: FORK
This call creates an exact clone of the calling process.
After the FORK, two processes- child and parent
have the same memory image, environment strings,
same everything!
Process Creation
The reason for this two step process is like a
reservation in bus ticket. The OS is alerted that
with the procedure. Secondly, the child
process gets plenty of time to decide whether
it’s going to purchase or decline that ticket!
Windows does not have such FORKING. It
uses CreateProcess system.
Process Termination
Sooner or later the new process will terminate-
1. Normal Exit (voluntary)
Simply, when you close a window on
Windows, the process(es) related to it have
their normal exit
Process Termination
2. Error Exit (voluntary)
How many times your compiler reported error to us
you during compiling? Screen oriented platforms like
Windows, however, uses a hybrid of Normal Exit and
Error Exit in such cases!
Process Termination