You are on page 1of 36

Introduction to DSs Lecture Notes

Chapter 3
Processes
Birhanie Ewnetu
bireuog@gmail.com
University of Gondar (UOG)
Computer Science Department

1 BireZman (bireuog@gmail.com) 10/24/2021


Outline

1) Introduction to Processes
2) Types of Processes (Processes in Early
Computer Systems and Distributed Systems)
3) Multithreading Usage (in Distributed Systems
and Non-Distributed Systems)
4) More Benefits of Multithreading
5) Code Migration

2 BireZman (bireuog@gmail.com) 10/24/2021


1) Introduction to Processes

What’s Process?
 Communication takes place between processes.
 From operating systems concept a process is
generally defined as a program in execution.

3 BireZman (bireuog@gmail.com) 10/24/2021


Process vs. Program
 A program by itself is not a process.
 A program is a passive entity, such as
executable file.
 Whereas, 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 the
executable file is loaded into memory.
o For example, by double clicking an icon
representing the executable file.

4 BireZman (bireuog@gmail.com) 10/24/2021


Process State
 As a process executes, it changes state.
 A process state is defined in part by the current
activity of that process.
 Each process may be in one of the following states:-
a) New – The process is being created.
b) Running – Instructions are being executed.
c) Waiting – The process is waiting for some event to
occur, such as I/O completion or reception of a
signal.
d) Ready – The process is waiting to be assigned to a
processor.
e) Terminated – The process has finished execution.

5 BireZman (bireuog@gmail.com) 10/24/2021


Figure: States of a Process

 Important to recognize that at any instant only one


process can be running on any processor.
 However many processes may be ready and waiting.

6 BireZman (bireuog@gmail.com) 10/24/2021


2) Types of Processes

I. Processes In Early Computer Systems


 Early computer systems allowed only one program to be
executed at a time.
 This program had a complete control of the
system.
 To accomplish a task, it had access to all the
systems resources (such as CPU time, memory,
files and I/O devices).
 Therefore, traditionally a process contained only a
single thread of control as it ran.
 The resources are allocated to the process either
when it is created or while it is executing.
7 BireZman (bireuog@gmail.com) 10/24/2021
II. Multithread Processes (vs. Single Thread)
 Usually, there are many processes executing concurrently,
so that processes should not interfere with each other.
 Sharing resources by processes is transparent and
this concurrency transparency has achieved at a
high price.
o Allocating resources for a new process and
context switching take time.
 A thread also executes independently from other
threads, but no need of a high degree of
concurrency transparency thereby resulting in better
performance.

8 BireZman (bireuog@gmail.com) 10/24/2021


 A process has an address space (containing program text
and data) and a single thread of control, as well as other
resources such as open files, child processes, accounting
information, etc.

Process-1 Process-2 Process-3

Three processes with One process with


one thread each. three threads
9 BireZman (bireuog@gmail.com) 10/24/2021
 Each thread has its own program counter, registers, stack,
and state.
 But all threads of a process share address space, global
variables and other resources such as open files, etc.

Figure: Illustrates difference between traditional single-threaded


process and a multithreaded processes.
10 BireZman (bireuog@gmail.com) 10/24/2021
Figure: Concepts Per Thread vs. Per Process

11 BireZman (bireuog@gmail.com) 10/24/2021


3) Multithreading Usage

 Threads take turns in running:-


 For example, threads allow multiple executions to take
place in the same process environment, referred as
multithreading.
 Multithreading is used both in distributed and non-
distributed Systems.

12 BireZman (bireuog@gmail.com) 10/24/2021


A. Multithreading in Non-Distributed Systems
 An example of multithread usage is in a word
processor, each thread are engaged in different parts
such as:-
 Interacting with the user.
 Formatting the page as soon as changes are
made.
 Timed savings (for auto recovery).
 Spelling and grammar checking.
 Etc.

13 BireZman (bireuog@gmail.com) 10/24/2021


B. Multithreading in Distributed Systems
 Multithreaded Clients
 Consider a web browser fetching different parts
of a page can be implemented as a separate
thread.
o Each opening its own TCP connection to
the server.
o Each can display the results as it gets its
part of the page.
 Parallelism can also be achieved for replicated
servers since each thread request can be
forwarded to separate replicas.

14 BireZman (bireuog@gmail.com) 10/24/2021


 Multithreaded Servers (Servers can be constructed in three
ways)
 Single-Threaded Process
o It gets a request, examines it, carries it out to
completion before getting the next request.
 Threads
o They are more important for implementing
servers; for example, a File Server.
o The dispatcher thread reads incoming requests
for a file operation from clients and passes it to
an idle worker thread.
 Finite-State Machine
o If threads are not available it gets a request,
examines it, tries to fulfill the request from
15
cache, else sends a request to the file system.
BireZman (bireuog@gmail.com) 10/24/2021
Figure: Thread Usage in A Multithreaded Web
Server

16 BireZman (bireuog@gmail.com) 10/24/2021


 As a summary

Model Characteristics
Single-threaded No parallelism, blocking system
process calls
Threads Parallelism, blocking system calls
(thread only)
Finite-state machine Parallelism, non blocking system
calls

17 BireZman (bireuog@gmail.com) 10/24/2021


4) More Benefits from Multithreading

 Let’s see four benefits from multithreaded programming:-


I. Responsiveness
II. Resource Sharing
III. Economy
IV. Utilization Of Multiprocessor Architectures

18 BireZman (bireuog@gmail.com) 10/24/2021


I. Responsiveness
 Multithreading an interactive application may allow a
program to continue running even if part of it is
blocked or is performing a lengthy operation, thereby
increasing responsiveness to the user.
 For instance, a multithreaded web browser could still
allow user interaction in one thread while an image
was being loaded in another thread.

19 BireZman (bireuog@gmail.com)
10/24/2021
II. Resource Sharing

 By default, threads share the memory and the


resources of the process to which they belong.
 The benefit of sharing code and data is that it
allows an application to have several different
threads of activity within the same address space.

20 BireZman (bireuog@gmail.com)
10/24/2021
III. Economy

 Allocating memory and resources for process creation is


costly, because threads share resources of the process to
which they belong.
 It is more economical to create and context-
switch threads.
 Empirically gauging the difference in overhead can be
difficult, but in general it is much more time consuming
to create and manage processes than threads.
 In Solaris, for example, creating a process is
about thirty times slower than is creating a thread,
and context switching is about five times slower.
21 BireZman (bireuog@gmail.com)
10/24/2021
IV. Utilization Of Multiprocessor Architectures

 The benefits of multithreading can be greatly increased


in a multiprocessor architecture, where threads may be
running in parallel on different processors.
 A single-threaded process can only run on one CPU, no
matter how many are available.
 Multithreading on a multi-CPU machine
increases concurrency.

22 BireZman (bireuog@gmail.com)
10/24/2021
5) Code Migration

 So far, we’ve discussed communication that concerned with


passing data.
 But we may pass also programs, even while running
and in heterogeneous systems.
 Code migration involves moving data as well:-
 When a program migrates while running its status,
pending signals and other environment variables
such as the stack and the program counter also have
to be moved.

23 BireZman (bireuog@gmail.com) 10/24/2021


Why Migrating Codes?
 There are many reasons for migrating codes, few are:-
 To Improve Performance: For example, moving
processes from heavily-loaded to lightly-loaded
machines (load balancing).
 To Reduce Communication: Moving a client
application that performs many database operations to
a server if the database resides on the server, then
send only results to the client.
 To Exploit Parallelism: This may be for nonparallel
programs, for example copies of a mobile program
(or a mobile agent) is called in search engines and
moving from site to site searching the Web.

24 BireZman (bireuog@gmail.com) 10/24/2021


Benefits of Code Migration

 In a distributed operating system, the users access remote


resources in the same way they access local resources.
 Data and process migration from one site to another is
under the control of the distributed operating system.
I. Data Migration
II. Computation Migration
III. Process Migration

25 BireZman (bireuog@gmail.com)
10/24/2021
I. Data Migration
 Suppose a user on site A wants to access data (e.g.; a file)
that reside at site B, then the system can transfer the data in
two basic methods.
a) First approach of data migration is to transfer the entire
file to site A.
 From that point on, all access to the file is local.
o When the user no longer needs access to the
file, a copy of the file (if it has been
modified) is sent back to site B.
o Even if only a modest change has been
made to a large file, all the data must be
transferred.
 This mechanism can be thought of as an
26 automated FTP system.
BireZman (bireuog@gmail.com) 10/24/2021
b) Second approach is to transfer to site A only those
portions of the file that are actually necessary for the
immediate task.
 If another portion is required later, another transfer
will take place.
 When the user no longer wants to access the file,
any part of it that has been modified must be sent
back to site B.
 note the similarity to demand paging.
o The Sun Microsystems network file system
(NF5) protocol uses this method.
o The Microsoft 5MB protocol (running on top
of either TCP/IP or the Microsoft
NetBEUIprotocol) also allows file sharing
27
over a network.
BireZman (bireuog@gmail.com) 10/24/2021
 Comparing the two data transfer approaches
 Clearly, if only a small part of a large file is being
accessed, the second approach is preferable.
 If significant portions of the file are being accessed,
however, it is more efficient to copy the entire file.
 In both methods, data migration includes more than
the mere transfer of data from one site to another.
 The system must also perform various data
translations if the two sites involved are not directly
compatible (for instance, if they use different
character-code representations or represent integers
with a different number or order of bits).

28 BireZman (bireuog@gmail.com) 10/24/2021


II. Computation Migration

 In some circumstances, we may want to transfer the


computation, rather than the data, across the system – this
approach is called computation migration.
 For example, consider a job that needs to access
various large files that reside at different sites, to
obtain a summary of those files.
 It would be more efficient to access the files at the
sites where they reside and return the desired results
to the site that initiated the computation.

29 BireZman (bireuog@gmail.com) 10/24/2021


 Generally, if the time to transfer the data is longer than the
time to execute the remote command, the remote command
should be used.
 Such a computation can be carried out in different ways,
suppose that process P wants to access a file at site A.
a) Access to the file is carried out at site A and could be
initiated by an RPC.
 An RPC uses a datagram protocol (UDP on the
Internet) to execute a routine on a remote
system.
 Process P invokes a predefined procedure at
site A.
 The procedure executes appropriately and then
returns the results to P.
30 BireZman (bireuog@gmail.com) 10/24/2021
b) Alternatively, process P can send a message to site A.
 The operating system at site A then creates a new
process Q whose function is to carry out the
designated task.
 When process Q completes its execution, it sends the
needed result back to P via the message system.
 In this scheme, process P may execute concurrently
with process Q and, in fact, may have several
processes running concurrently on several sites.

31 BireZman (bireuog@gmail.com) 10/24/2021


 Both methods could be used to access several files residing
at various sites.
 One RPC might result in the invocation of another
RPC or even in the transfer of messages to another
site.
 Similarly, process Q could, during the course of its
execution, send a message to another site, which in
turn would create another process.
 This process might either send a message back to Q
or repeat the cycle.

32 BireZman (bireuog@gmail.com) 10/24/2021


III. Process Migration

 A logical extension of computation migration is


process migration.
 When a process is submitted for execution, it is
not always executed at the site at which it is
initiated.
 The entire process, or parts of it, may be
executed at different sites.

33 BireZman (bireuog@gmail.com) 10/24/2021


 This process migration scheme is used for several reasons,
such as:-
a) Load Balancing
 The processes (or subprocesses) may be
distributed across the network to even the
workload.
b) Computation Speedup
 If a single process can be divided into a
number of subprocesses that can run
concurrently on different sites, then the total
process turnaround time can be reduced.

34 BireZman (bireuog@gmail.com) 10/24/2021


c) Hardware Preference
 The process may have characteristics that make it
more suitable for execution on some specialized
processor (such as matrix inversion on an array
processor, rather than on a microprocessor).
d) Software Preference
 The process may require software that is available at
only a particular site, and either the software cannot
be moved, or it is less expensive to move the process.
e) Data Access
 Just as in computation migration, if the data being
used in the computation are numerous, it may be
more efficient to have a process run remotely than to
transfer all the data.
35 BireZman (bireuog@gmail.com) 10/24/2021
exit.chapter(3);

36 BireZman (bireuog@gmail.com) 10/24/2021

You might also like