Sie sind auf Seite 1von 31

Operating Systems

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

 waiting: The process is waiting for some


event to occur
 ready: The process is waiting to be assigned
to a processor
 terminated: The process has finished
execution
Diagram of Process State
Process Control Block (PCB)
Information associated with each
process
 Process state

 Program counter

 CPU registers

 CPU scheduling information

 Memory-management information

 I/O status information


Process Control Block (PCB)
CPU Switch From Process to
Process
Process Scheduling Queues

 Job queue – set of all processes in the


system
 Ready queue – set of all processes residing
in main memory, ready and waiting to
execute
 Device queues – set of processes waiting
for an I/O device
 Processes migrate among the various queues
Representation of Process
Scheduling
Schedulers
 Long-term scheduler (or job
scheduler) – selects which processes
should be brought into the ready
queue
 Short-term scheduler (or CPU
scheduler) – selects which process
should be executed next and
allocates CPU
Schedulers (Cont.)
 Short-term scheduler is invoked very
frequently (milliseconds)  (must be
fast)
 Long-term scheduler is invoked very
infrequently (seconds, minutes) 
(may be slow)
 The long-term scheduler controls the
the number of processes in the memory
degree of multiprogramming
Mathematics!
 If a process is required 10 milliseconds to be decided
for a GO and it takes 100 milliseconds to execute then
the CPU usage for that particular task is-

110 ms process requires 10 ms to be decided


1 ms process requires 10/110 ms to be decided
100 ms process requires ??? ms to be decided

9% of the CPU was used to accomplish that process


Mathematics!
 If a process is required 100 seconds to be decided for a
GO and it takes 1000 seconds to execute then the CPU
usage for that particular task is-

1100 s process requires 100 s to be decided


1 s process requires 100/1100 s to be decided
100 s process requires ??? s to be decided

9% of the CPU was used to accomplish that process


Mathematics!

 Which process should be


scheduled by Long term scheduler?
Justify your statement
The Process Model
 Conceptually, each process has its own virtual
CPU
 In reality, the real CPU switches back and forth
from process to process
 This procedure is called pseudoparallelism.
Process A

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

3. Fatal Error (Non-voluntary)


This error is caused by the process itself,
normally due to the program bug. Referencing
non-existing memory location or divide by
zero problems cause such errors and process
termination
Process Termination
4. Killed by another process
In UNIX, the system call is KILL. In
Windows, the call is TerminateProcess. In
both cases, the KILLER must have the proper
authorization to kill the KILLEE.

Das könnte Ihnen auch gefallen