0% found this document useful (0 votes)
23 views34 pages

Processes

Uploaded by

Md.Tanvir Ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
Download as ppt, pdf, or txt
0% found this document useful (0 votes)
23 views34 pages

Processes

Uploaded by

Md.Tanvir Ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1/ 34

.

Processes
Operating System Objectives
• Convenience
Makes the computer more convenient to use
• Efficiency
Allows computer system resources to be
used in an efficient manner
• Ability to evolve
Permit effective development, testing, and
introduction of new system functions without
interfering with service

2
Main OS Concepts
• Processes
• Memory Management
• Information protection and security
• Scheduling and resource
management
• System structure

3
What is a Process?

• A computer program is a set of instructions for a computer to


perform a specific task.
• Programs are written in a programming language
• A process is a program during execution.
• Program = static file (image)
• Process = executing program = program + execution state.
• A process is the basic unit of execution in an operating system
• Each process has a number, its process identifier (pid).

4
Figure 3.1 Process in memory

5
Figure 3.1 Process in memory.

A process includes:
Text: Contain program counter – specifying next
instruction to be executed under that process.
Data section: Containing global variables.
Heap: Which is memory that is dynamically allocated
during process run time.
Stack: Contains temporary data (such as function
parameters, return addresses, and local variables).

6
Cont.

We emphasize that a program by itself is not a


process. A program is a passive entity, such as a file
containing a list of instructions stored on disk (often
called an executable file).
In contrast, a process is an active entity, with a
program counter specifying the next instruction to
execute and a set of associated resources.
A program becomes a process when an executable
file is loaded into memory.

7
Cont.

Two common techniques for loading executable files are

1.Double-clicking an icon representing the executable file .

1.Entering the name of the executable file on the command line


(as in prog.exe or a.out).

8
3.1.2 Process State

As a process executes, it changes state


® New: The process is being created.
® Ready: The process is waiting to be assigned to a processor.
® Running: Instructions are being executed.
® Waiting: The process is waiting for some event to occur.
® Terminated: The process has finished execution.
9
3.1.2 Process State

10
3.1.3 Process Control Block

Each process is represented in the operating system by a process control block


(PCB)—also called a task control block. A PCB is shown in Figure. It contains
many pieces of information associated with a specific process, including these:
Process state
Program counter
CPU registers
CPU scheduling information
Memory-management information
Accounting information
I/O status information

11
Cont.

A PCB contains the following Information:


– Process state: new, ready, …
– Program counter: indicates the address of the next instruction to be executed
for this program.
– CPU registers: includes accumulators, stack pointers, …
– CPU scheduling information: includes process priority, pointers to
scheduling queues.
– Memory-management information: includes the value of base and limit
registers (protection) …
– Accounting information: includes amount of CPU and real time used,
account numbers, process numbers, …
– I/O status information: includes list of I/O devices allocated to this process,
a list of open files, …

12
3.2.1 Scheduling Queues

»Each rectangular box represents a queue.


»Two types of queues are present:
» The ready queue and a set of device queues.
»The circles represent the resources that serve the queues.
» The arrows indicate the flow of processes in the system.
13
Cont.

 As processes enter the system, they are put into a job


queue, which consists of all processes in the system.
 The processes that are residing in main memory and
are ready and waiting to execute are kept on a list
called the ready queue.
 Suppose the process makes an I/O request to a shared
device, such as a disk. Since there are many processes
in the system, the disk may be busy with the I/O
request of some other process. The process therefore
may have to wait for the disk. The list of processes
waiting for a particular I/O device is called a device
queue. 14
Cont.

A new process is initially put in the ready queue. It waits there until it is
selected for execution, or dispatched.
Once the process is allocated the CPU and is executing, one of several events
could occur:
1.The process could issue an I/O request and then be placed in an I/O queue.
2.The process could create a new child process and wait for the child’s
termination.
3.The process could be removed forcibly from the CPU, as a result of an
interrupt, and be put back in the ready queue.
In the first two cases, the process eventually switches from the waiting state
to the ready state and is then put back in the ready queue. A process continues
this cycle until it terminates, at which time it is removed from all queues and
has its PCB and resources deallocated.

15
3.2.2 Schedulers

A process migrates among the various scheduling queues


throughout its lifetime. The operating system must select,
for scheduling purposes, processes from these queues in
some fashion. The selection process is carried out by the
appropriate scheduler.

16
Types of Scheduler

Long-term scheduler (or job scheduler) –


Selects which processes should be brought into the
ready queue (i.e, selects processes from pool (disk) and
loads them into memory for execution).
Short-term scheduler (or CPU scheduler) –
Selects which process should be executed next and
allocates CPU (i.e, selects from among the processes that
are ready to execute, and allocates the CPU to one of
them) .

17
Cont.

Medium-term scheduler :
Some operating systems, such as time-sharing systems, may introduce an
additional, intermediate level of scheduling.
The key idea behind a medium-term scheduler is that sometimes it can be
advantageous to remove a process from memory (and from active
contention for the CPU) and thus reduce the degree of
multiprogramming.
Later, the process can be reintroduced into memory, and its execution can
be continued where it left off. This scheme is called swapping.
The process is swapped out, and is later swapped in, by the medium-term
scheduler.

18
Cont.

Running process may become suspended if it makes an I/O


request. Suspended processes cannot make any progress towards
completion. In this condition, to remove the process from memory
and make space for other process, the suspended process is moved
to the secondary storage. This process is called swapping, and the
process is said to be swapped out or rolled out. Swapping may be
necessary to improve the process mix.

19
3.3.1 Process Creation

During the course of execution, a process may create several new


processes.
The creating process is called a parent process, and the new processes are
called the children of that process. Each of these new processes may in
turn create other processes, forming a tree of processes.

Most operating systems (including UNIX, Linux, and Windows) identify


processes according to a unique process identifier (or pid), which is
typically an integer number.

20
3.3.1 Process Creation
Figure 3.8 illustrates a typical process tree for the Linux operating system,
showing the name of each process and its pid. (We use the term process rather
loosely, as Linux prefers the term task instead.) The init process (which always
has a pid of 1) serves as the root parent process for all user processes. Once the
system has booted, the init process can also create various user processes, such
as a web or print server, an ssh server, and the like.

21
Cont.

When a process creates a child process, that child process


will need certain resources (CPU time, memory, files, I/O
devices) to accomplish its task.
A child process may be able to obtain its resources

1.Directly from the operating system, or


2.Tt may be constrained to a subset of the resources of
the parent process.

22
3.3.2 Process Termination

A process terminates when it finishes executing its final


statement and asks the operating system to delete it by
using the exit() system call. At that point, the process may
return a status value (typically an integer) to its parent
process (via the wait() system call).
All the resources of the process—including physical and
virtual memory, open files, and I/O buffers—are
deallocated by the operating system.

23
Cont.

A parent may terminate the execution of one of its children for a variety of
reasons, such as these:
»The child has exceeded its usage of some of the resources that it has been
allocated. (To determine whether this has occurred, the parent must have a
mechanism to inspect the state of its children.)
»The task assigned to the child is no longer required.
»The parent is exiting, and the operating system does not allow a child to
continue if its parent terminates.
Some systems do not allow a child to exist if its parent has terminated. In
such systems, if a process terminates (either normally or abnormally), then
all its children must also be terminated. This phenomenon, referred to as
cascading termination, is normally initiated by the operating system.

24
3.4 Interprocess Communication

Processes executing concurrently in the operating system may be


either independent processes or cooperating processes.
A process is independent if it cannot affect or be affected by the
other processes executing in the system.
Any process that does not share data with any other process is
independent.
A process is cooperating if it can affect or be affected by the other
processes executing in the system. Clearly, any process that shares
data with other processes is a cooperating process.

25
Cont.

There are several reasons for providing an environment that allows


process cooperation:
• Information sharing: Since several users may be interested in the
same piece of information (for instance, a shared file), we must provide
an environment to allow concurrent access to such information.
• Computation speedup: If we want a particular task to run faster, we
must break it into subtasks, each of which will be executing in parallel
with the others. Notice that such a speedup can be achieved only if the
computer has multiple processing cores.
• Modularity: We may want to construct the system in a modular
fashion, dividing the system functions into separate processes or threads.
• Convenience. Even an individual user may work on many tasks at the
same time. For instance, a user may be editing, listening to music, and
compiling in parallel.
26
Cont.

Cooperating processes require an interprocess


communication (IPC) mechanism that will allow them
to exchange data and information.
There are two fundamental models of interprocess
communication:
1. Shared memory
2. Message passing

27
Cont.

1. Shared memory
2. Message passing

28
3.4.1 Shared-Memory Systems

Shared memory requires communicating processes to


establish a region of shared memory. Typically, a shared-
memory region resides in the address space of the process
creating the shared-memory segment. Other processes that
wish to communicate using this shared-memory segment
must attach it to their address space. Recall that, normally, the
operating system tries to prevent one process from accessing
another process’s memory. Shared memory requires that two
or more processes agree to remove this restriction. They can
then exchange information by reading and writing data in the
shared areas.

29
Cont.

To illustrate the concept of cooperating processes, let’s


consider the producer–consumer problem, which is a
common paradigm for cooperating processes.
A producer process produces information that is
consumed by a consumer process.
For example, a compiler may produce assembly code
that is consumed by an assembler. The assembler, in turn,
may produce object modules that are consumed by the
loader.

30
Cont.

The producer–consumer problem also provides a useful


metaphor for the client–server paradigm. We generally
think of a server as a producer and a client as a consumer.
For example, a web server produces (that is, provides)
HTML files and images, which are consumed (that is,
read) by the client web browser requesting the resource.
The producer and consumer must be synchronized, so
that the consumer does not try to consume an item that
has not yet been produced.

31
3.4.2 Message-Passing Systems

Message passing provides a mechanism to allow


processes to communicate and to synchronize their
actions without sharing the same address space. It is
particularly useful in a distributed environment, where
the communicating processes may reside on different
computers connected by a network.
For example, an Internet chat program could be
designed so that chat participants communicate with one
another by exchanging messages.

32
Cont.

A message-passing facility provides at least two


operations:
send(message) receive(message)

If processes P and Q want to communicate, they must


send messages to and receive messages from each other:
a communication link must exist between them. This
link can be implemented in a variety of ways.

33
Cont.

Message passing is useful for exchanging smaller


amounts of data, because no conflicts need be avoided.
Message passing is also easier to implement in a
distributed system than shared memory.
Shared memory can be faster than message passing,
since message-passing systems are typically implemented
using system calls and thus require the more time-
consuming task of kernel intervention.

34

You might also like