DS Lecture 3 (1)
DS Lecture 3 (1)
DS Lecture 3 (1)
010101010101010100010100010111001010101010010101010101010001010100010111001
010101010010101010101010100010100010111001010101010010101010101010100010100
Lecture
010111001010101010010101010101010100010100010111001010101010010101010101010
100010100010111001010101010010101010101010100010100010111001010101010010101
010101010100010100010111001010101010010101010101010100010100010111001010101
010010101010101010100010100010111001010101010010101010101010100010100010111
Three in
001010101010010101010101010100010100010111001010101010010101010101010100010
Processes
100010111001010101010010101010101010100010100010111001010101010010101010101
010100010100010111010101010010101010100101010101010101000101000101 Since
0101010101010101010101010101010101010101010
DS
101010101000101000101110010101010100101010101010101000101000101110010101010
100101010101010101000101000101110010101010100101010101010101000101000101110
01010101010010101010101010100010100010111001010101010010
BY Basha K | Faculty of Computing and Software
Contents
•After accomplishing of this chapter, Students will be able to understand:
Definition of Processes in OS and DS Perspective
Concepts of Multitasking
Code Migration
Software Agents
Definition of Process (OS….Definition)
• A process is a program that is loaded into memory, found under executing and it
is a collection of one or more threads (What is thread?) and associated system
resources.
• Process can create one or more other processes referred to as child processes and
these processes in turn can create child processes.
Cont…
• A process is often defined as a program in execution, which is currently
being executed on one of the operating system's virtual processors.
• In other words, the fact that multiple processes may be concurrently sharing
the same CPU and other hardware resources is made transparent.
• In most traditional OS, each process has an address space, a single thread of
control and other processing resources.
• User space: is that set of memory locations in which user processes run and it is
the memory area where application software and some drivers execute in the
operating system.
Functions of a Kernel
• Access Computer Resource: A Kernel can access various computer resources like the CPU,
• Resource Management: It is the duty of a Kernel to share the resources between various
process in such a way that there is uniform access to the resources by every process.
• Memory Management: Every process needs some memory space. So, memory must be
allocated and deallocated for its execution. All these memory management is done by a Kernel.
• Device Management: The peripheral devices connected in the system are used by the
• It is therefore deeply related to the OS capability for managing shared resources, and in
particular for deciding conflicts resulting from resource over-commitment.
• In a multitasking environment, the totality of the computer’s resources (memory, files, CPU
time) are allocated to different applications, and they are managed in such a way that each one
of them gets a share according to specific priority policies.
Cont…
Cont…
• Threads are quite useful for distributed system applications and many systems interact using a
client/server model of communication where a server process listens for client requests, executes
• This would keep a number of buffered unanswered requests waiting indeterminately until the
server finished with earlier ones and the outstanding requests may timeout giving the client the
execute.
• Requests then execute asynchronously under the control of the operating system and
the listener process could also provide an immediate initial response to the client if
required.
• The Problem However is that process creation can be quite slow as the operating
system has to find sufficient free memory space for the process and set up other parts
• This is a more remarkable approach from the operating system's point of view as it is a more efficient use of
system resources.
• Coordination and synchronization between the cooperating parts of the server process are achieved more
efficiently with shared memory mechanisms.
• So, Threads allow parallelism to be combined with the easily understood blocking communication of the
client/server model.
Cont…
Single vs Multi Thread Process
Difference Between Process vs Thread
Definition:
• Process: Independent program in execution with its own memory space and
resources.
• Thread: Smaller unit of a process that shares memory space and resources.
Communication:
Memory Space: • Process: Requires inter-process
• Process: Own memory space. communication (IPC), which is complex and
• Thread: Shares memory space with other slower.
threads in the same process. • Thread: Easy communication through
shared memory.
Overhead: Isolation:
• Process: Higher overhead due to context • Process: Isolated; one process crashing
switching. does not affect others.
• Thread: Lower overhead; faster context • Thread: Less isolated; crashing one thread
switching. can impact the entire process.
Creation: Use Case:
• Process: Best for running separate
• Process: More time-consuming to create.
applications or services.
• Thread: Faster to create and manage. • Thread: Suitable for concurrent tasks
within the same application.
Why Thread in Distributed System?
•An important property of threads is that they can provide a convenient means of allowing
blocking system calls without blocking the entire process in which the thread is running.
•This property makes threads particularly attractive to use in distributed systems as it makes it
much easier to express communication in the form of maintaining multiple logical connections
at the same time.
•We illustrate this point by taking a closer look at Multithreaded In Clients and Servers side,
respectively.
Multithreaded Servers
•Practice shows that multithreading not only simplifies server code considerably, but also makes
it much easier to develop servers that exploit parallelism to attain high performance, even on
uniprocessor systems.
•Multithreaded Server: A server having more than one thread is known as Multithreaded Server.
•When a clients sends the requests, a threads is generated through which a user can
communicate with the server.
•We need to generate multiple threads to accept multiple requests from multiple clients at the
same time.
Cont…
Advantage of Thread
Useful for Clients: if a client wants a file to be replicated on multiple servers, it can have
Handle Signals: such as interrupts from the keyboard and instead of letting the signal
interrupt the process, one thread is dedicated full time to waiting for signals.
Producer-Consumer Problems: are easier to implement using threads because threads can
Virtualization Allows
Why Do We Need Threads?
• They are Easier to create and destroy than processes: since they do not have
any resources attached to them.
spreadsheet.
• It waits for an incoming request from a client and subsequently ensures that the request is taken
care of, after which it waits for the next incoming request.
• In the case of an iterative server, the server itself handles the request and, if necessary, returns a
response to the requesting client.
• A concurrent server does not handle the request itself, but passes it to a separate thread or
another process, after which it immediately waits for the next incoming request.
• Each server listens to a specific end point. How do clients know the end point of
a service?
• The approach is to globally assign end points for well-known services. For
example, servers that handle Internet FTP requests always listen to TCP port 21.
• Likewise, an HTTP server for the World Wide Web will always listen to TCP port
80.
Servers and Design Issues…
server, the server will tear down the connection assuming that the client had
crashed.
• Code Migration is when programs are moved from one machine to another, often moving parts
mobile agents.
• Code Migration increases scalability, improves performance, and provides flexibility of the
system.
Cont…
• Traditionally, code migration in distributed systems took place in the form of
process migration in which an entire process was moved from one machine to another.
• The basic idea is that overall system performance can be improved if processes are
moved from heavily-loaded to lightly-loaded machines.
• Code migration in the broadest sense deals with moving programs between machines,
with the intention to have those programs be executed at the target.
particular environment.
• It is inhibited by other processes and agents, but is also able to learn from
its experience in functioning in an environment over a long period of time.
Examples
Thank You!
Q?