You are on page 1of 72

Process and thread

BCA_DS_3_DN_NC(dineupane8@gmail.com) 1
Process
• Program that is being executed in CPU
• The OS helps you to create, schedule, and terminates the processes
which is used by CPU.
• Creation of each process requires separate system calls for each
process.
• The other processes created by the main process are called child
process

BCA_DS_3_DN_NC(dineupane8@gmail.com) 2
Process

• It is an isolated execution entity and does not share data and


information.
• Processes use the IPC(Inter-Process Communication) mechanism for
communication that significantly increases the number of system
calls.

BCA_DS_3_DN_NC(dineupane8@gmail.com) 3
Process
• Processes are unique in that they don’t share data and information;
they’re isolated execution entities. In short, a process has its own
stack, memory, and data.

• In order to create more than one process, we need to use separate


system calls. Additionally, more system calls are required for process
management.

BCA_DS_3_DN_NC(dineupane8@gmail.com) 4
Multithreading benefits

BCA_DS_3_DN_NC(dineupane8@gmail.com) 6
Thread
• Thread is an execution unit that is part of a process. Also called basic unit
of CPU utilization.
• A thread consists of thread id, program counter, register set and a stack.
• It shares with others threads belongings to the same process its code
section, data section, files and other operating system resources
• A process can have multiple threads, all executing at the same time. It is a
unit of execution in concurrent programming.
• A thread is lightweight and can be managed independently by a scheduler.
It helps you to improve the application performance using parallelism.

BCA_DS_3_DN_NC(dineupane8@gmail.com) 7
Properties of thread
• Single system call can create more than one thread
• Threads share data and information.
• Thread management consumes very few, or no system calls because
of communication between threads that can be achieved using
shared memory.

BCA_DS_3_DN_NC(dineupane8@gmail.com) 8
Thread vs process
• Unlike processes, threads share data and information. They do,
however, have their own stack.
• We can create more than one thread by using just one system call. To
further simplify things, thread management requires few or even no
system calls because we don’t need extra mechanisms such as IPC to
maintain communication between threads.

BCA_DS_3_DN_NC(dineupane8@gmail.com) 9
Thread vs process

BCA_DS_3_DN_NC(dineupane8@gmail.com) 10
User level vs kernel level thread

User thread are implemented by users. kernel threads are implemented by OS.

OS doesn’t recognize user level threads. Kernel threads are recognized by OS.

Implementation of User threads is easy. Implementation of Kernel thread is complicated.

Context switch time is less. Context switch time is more.

If one user level thread perform blocking operation If one kernel thread perform blocking operation then
then entire process will be blocked. another thread can continue execution.

BCA_DS_3_DN_NC(dineupane8@gmail.com) 16
Process cycle

BCA_DS_3_DN_NC(dineupane8@gmail.com) 17
Process states

New State
• Process it submitted to the process queue, it in turns
acknowledges submission.
• Once submission is acknowledged, the process is given new
status.

BCA_DS_3_DN_NC(dineupane8@gmail.com) 18
• Ready State

• It then goes to Ready State, at this moment the process is


waiting to be assigned a processor by the OS

BCA_DS_3_DN_NC(dineupane8@gmail.com) 19
Running – Process
getting executing

Wait – Process waiting


for signal

Terminated – Process
execution completed

BCA_DS_3_DN_NC(dineupane8@gmail.com) 20
BCA_DS_3_DN_NC(dineupane8@gmail.com) 21
Virtualization
• Virtualization technology is the process of creating a virtual platform
with the aid of virtualization software
• These software acts as a layer between primary systems and the
secondary systems or virtual systems
• It allows the virtual systems to access the resources of the primary
systems such as RAM, ROM, Storage, CPU,etc

BCA_DS_3_DN_NC(dineupane8@gmail.com) 22
Virtualization

BCA_DS_3_DN_NC(dineupane8@gmail.com) 23
Virtualization terminology
Hypervisor / virtual machine manager (VMM)
• Hypervisor also known as a virtual machine monitor, is a process that
creates and runs virtual machine(VMs)
• It allows some of the operating systems to share a single host and its
hardware.
• This hypervisor manages requests by the virtual machines to access
the hardware resources like RAM, CPU, etc

BCA_DS_3_DN_NC(dineupane8@gmail.com) 24
Virtualization terminology
• Host machine
• A host machine is the physical machine running the virtualization
software
• It contains the physical resources, such as memory, hard disk space, and
CPU, and other resources,
• Virtual machine
• The virtual machine is the virtualized representation of a physical
machine that is run and maintained by the virtualization software.

• Virtualization software
• Virtualization software is a generic term denoting software that
allows a user to run virtual machines on a host machine

BCA_DS_3_DN_NC(dineupane8@gmail.com) 25
• Guest OS:
• A guest OS is an operating system that runs in a virtual
environment.
• the guest OS uses hardware resources allocated dynamically
through a hypervisor or similar intermediary software.

BCA_DS_3_DN_NC(dineupane8@gmail.com) 26
BCA_DS_3_DN_NC(dineupane8@gmail.com) 27
Types of virtualization
• Server virtualization
• Desktop virtualization
• Application virtualization
• Storage virtualization
• Network virtualization

BCA_DS_3_DN_NC(dineupane8@gmail.com) 28
• A server is called as virtualized server when a single physical
computing machine is made as multiple virtual machines
• Each VM has its own virtual CPU, memory and peripheral interfaces
and is capable of running its own OS
• server virtualization breaks through the "one application, one server"
barrier and facilitates the consolidation of numerous servers into one
physical server.
• Amazon‘s EC2 Server (Elastic Compute Cloud 2) is a very good
example of server virtualization.

BCA_DS_3_DN_NC(dineupane8@gmail.com) 30
BCA_DS_3_DN_NC(dineupane8@gmail.com) 31
BCA_DS_3_DN_NC(dineupane8@gmail.com) 32
Advantage of server virtualization
• Reduce operational costs
• Reduce maintenance disruption

BCA_DS_3_DN_NC(dineupane8@gmail.com) 33
Disadvantages
• Only a few processors that support virtualization can be used to
virtualize servers.
• b. The resource allocation for each virtual system needs to be planned
carefully.
• If very less resource are allocated, the application performance might
be affected and if too much resources are allocated, it will result in
under-utilization.

BCA_DS_3_DN_NC(dineupane8@gmail.com) 34
Desktop virtualization
• The phrase “work from anywhere ” is practically possible because of
desktop virtualization it provide work convenience and security.
• It enables us to remotely access the data from anywhere and anytime
through any device.
• It provides a lot of flexibility and feasibility for employee and the data
is safe and secure as it is stored at a centralized location.

BCA_DS_3_DN_NC(dineupane8@gmail.com) 35
Desktop virtualization

BCA_DS_3_DN_NC(dineupane8@gmail.com) 36
• Remote (Server-Hosted) Desktop Virtualization: In this model, the
operating environment is hosted on a server in the data center and
accessed by the end user across a network. Users connect to the server via
connection brokers and receive their user interface via standard protocols,
such as Remote Desktop Protocol. VMware Inc. is among the leaders in this
market.
• Local (Client-Hosted) Desktop Virtualization: In this model, the operating
environment runs locally on the user's physical personal computer
hardware and involves multiple flavors of client-side virtualization
techniques that can monitor and protect the execution of the end user
system. generally ―hypervisor‖ software installed on the client device
allows one desktop to run multiple operating systems. Top vendors in this
market include VMware Inc.,
BCA_DS_3_DN_NC(dineupane8@gmail.com) 37
Advantages of Desktop Virtualization:
Anywhere, Anytime Access: Empowers users with ondemand access to
their virtual desktops when they need it, where they need it
Better Management and Control: Increases administrator's control
over desktop configurations (but end user may have some limitations)
Enhanced Security: Desktops with applications and data are hosted
within the datacenter – protecting sensitive information that would be
compromised with stolen laptops or PCs

BCA_DS_3_DN_NC(dineupane8@gmail.com) 38
Disadvantages of desktop virtualization
• If the host server fails, users cannot access their virtual desktops
• Peripherals on older devices may be difficult to support
• Centralization means less customization for end users(for server
hosted desktop virtualization)

BCA_DS_3_DN_NC(dineupane8@gmail.com) 39
Application virtualization

BCA_DS_3_DN_NC(dineupane8@gmail.com) 40
Storage virtualization
• It is the pooling of the physical storage from multiple network storage
devices into what appears to be a single storage device that is
managed from a central console.
• Virtual storage is commonly used in storage area network

BCA_DS_3_DN_NC(dineupane8@gmail.com) 41
Storage virtualization

BCA_DS_3_DN_NC(dineupane8@gmail.com) 42
Storage virtualization
• Storage virtualization means that applications can use storage
without any concerns for where it resides, what the technical
interface is , how it has been implemented, which platform it uses,
and how much of it is available
• Distance: remote storage devices appear local
• Size: multiple smaller volume appear as a single large volume
• Spread data is spread over multiple physical disks
• File system: windows, linux, and unix all use same storage device.
• Advantage--?

BCA_DS_3_DN_NC(dineupane8@gmail.com) 43
Task
• Write( in short) the concepts of application virtualization and network
virtualization

BCA_DS_3_DN_NC(dineupane8@gmail.com) 44
Network virtualization
• Network virtualization refers to virtually pooling and managing all the
available network resources such as IP’s switches, routers, etc via
means of tools such as routing tables in real time and each channel is
independently secure and distinct from one another.

BCA_DS_3_DN_NC(dineupane8@gmail.com) 45
Client (anatomy )

BCA_DS_3_DN_NC(dineupane8@gmail.com) 46
Network user interface
• A major task of client machines is to provide the means for users to
interact with remote servers
• There are roughly two ways in which this interaction can be
supported.
• First, for each remote service the client machine will have a separate
counterpart that can contact the service over the network.
• needs to synchronize with a remote server/service. In this case, an
application-level protocol will handle the synchronization,

BCA_DS_3_DN_NC(dineupane8@gmail.com) 47
Network User interface

BCA_DS_3_DN_NC(dineupane8@gmail.com) 48
Network user interface
• A second solution is to provide direct access to remote services by
only offering a convenient user interface.
• Effectively, this means that the client machine is used only as a
terminal with no need for local storage, leading to an application
neutral solution as shown in Fig. 3-8(b)
• Example X window system

BCA_DS_3_DN_NC(dineupane8@gmail.com) 49
Client side software for distributed
transparency
• Client software comprises more than just user interfaces
• In many cases, parts of the processing and data level in a client-server
application are executed on the client side as well.
• In these cases, the user interface is a relatively small part of the client
software, in contrast to the local processing and communication
facilities
• Besides the user interface and other application-related software,
client software comprises components for achieving distribution
transparency

BCA_DS_3_DN_NC(dineupane8@gmail.com) 50
Location transparency
• There are different ways to handle location, migration, and relocation
transparency
• In many cases, cooperation with client-side software is also
important.
• For example, when a client is already bound to a server, the client can
be directly informed when the server changes location. In this case,
the client's middleware can hide the server's current geographical
location from the user, and also transparently rebind to the server if
necessary
• At worst, the client's application may notice a temporary loss of
performance.
BCA_DS_3_DN_NC(dineupane8@gmail.com) 51
Replication transparency
• In a similar way, many distributed systems implement replication
transparency by means of client-side solutions.
• For example, imagine a distributed system with replicated servers,
Such replication can be achieved by forwarding a request to each
replica.
• Client-side software can transparently collect all responses and pass a
single response to the client application.

BCA_DS_3_DN_NC(dineupane8@gmail.com) 52
Replication transparency

BCA_DS_3_DN_NC(dineupane8@gmail.com) 53
Failure transparency
• Finally, consider failure transparency.
• Masking communication failures with a server is typically done
through client middleware.
• For example,
• client middleware can be configured to repeatedly attempt to connect to a
server,
• or perhaps try another server after several attempts.
• There are even situations in which the client middleware returns data it had
cached during a previous session,

BCA_DS_3_DN_NC(dineupane8@gmail.com) 54
Server

BCA_DS_3_DN_NC(dineupane8@gmail.com) 55
Server
• A server can serve multiple clients, and a single client can use
multiple servers.
• A client process may run on a same device or may connect over a
network to a server .

BCA_DS_3_DN_NC(dineupane8@gmail.com) 56
General server design issues
• Concurrent vs iterative server
• Contacting a server: identifying endpoints
• Interrupting a server
• Stateful vs stateless server

BCA_DS_3_DN_NC(dineupane8@gmail.com) 57
Iterative server

BCA_DS_3_DN_NC(dineupane8@gmail.com) 58
Concurrent server

BCA_DS_3_DN_NC(dineupane8@gmail.com) 59
Contacting a server: identifying endpoints
How do a client bind to a server/how do client know the end point?

→client connects to a endpoints (also called port) to the server machine

• Three approaches to get the endpoints


1. Statically assigned endpoints for well known services
E.g. HTTP: 80, FTP: 21
2. Dynamically assigned endpoints but a special daemon listening to a well
known port
3. Superserver : listening to a set of ports
BCA_DS_3_DN_NC(dineupane8@gmail.com) 60
• There are many services that do not need pre-assigned end points
• Server can use end points that is dynamically assigned by its local
operating system
• Client have to first look up the end-points
• One solution
• Have special daemon running on each machine (server)
• The daemon keeps the track of current end points of each
service(implemented by co-located servers)
• Client will first contact daemon for , request end points, then contact
specific server
BCA_DS_3_DN_NC(dineupane8@gmail.com) 61
• Next solution
• Have a separate super server listening to each end points associated
with a specific service
• For e.g inetd daemon in LINUX

BCA_DS_3_DN_NC(dineupane8@gmail.com) 62
BCA_DS_3_DN_NC(dineupane8@gmail.com) 63
BCA_DS_3_DN_NC(dineupane8@gmail.com) 64
Interrupting server

BCA_DS_3_DN_NC(dineupane8@gmail.com) 65
Interrupting a server
• Example consider a user who has just decided to upload a huge file
on a FTP server
• Suddenly realized it is a wrong file
• You want to interrupt the server
• But how?

BCA_DS_3_DN_NC(dineupane8@gmail.com) 67
Interrupting a server
• One approach is just break the connection between client and server
• The server will tear down old connection thinking the client has crashed.
• Better approach
Send out of band data which is the data that is processed by the server
Before processing any other data from that client
Out of band data can be send through
Another channel(control channel ,data channel)
Another solution is to send out-of-band data across the same
connection through which the client is sending the original request.

BCA_DS_3_DN_NC(dineupane8@gmail.com) 68
Stateless and stateful server

BCA_DS_3_DN_NC(dineupane8@gmail.com) 69
Stateless server
• Stateless server
• Stateless server maintains no information on the current connection
to the server
• Advantages: Easy to recover from the failure because there is no state
that must be restored
• A failed server can simply restart after a crash and immediately
provide a service

BCA_DS_3_DN_NC(dineupane8@gmail.com) 70
Stateful server
• Stateful server maintains the information on the current connection
to the server
• Advantage :every time they perform an operation , the size of the
message to and from the server can be significantly decrease.
• Likewise the server can make the use of the knowledge of access
pattern to perform read ahead and do other optimizations
• Stateful servers can also offers extra services such as file locking

BCA_DS_3_DN_NC(dineupane8@gmail.com) 71
BCA_DS_3_DN_NC(dineupane8@gmail.com) 72
BCA_DS_3_DN_NC(dineupane8@gmail.com) 73
BCA_DS_3_DN_NC(dineupane8@gmail.com) 74
Code migration
• Code migration is the transfer of code from one machine to another
• 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 execution status of the program pending signals, other parts of the
environments must be moved as well.
• Entire process moved from one process to another
• costly and intricate task, and there had better be a good reason for doing so:
performance

BCA_DS_3_DN_NC(dineupane8@gmail.com) 75
Why code migration?
• The basic idea is that overall system performance can be improved if
processes are moved from heavily-loaded to lightly-loaded machines.
• Load is often expressed in terms of the CPU queue length or CPU utilization
• In generally makes sense to process data close to where those data
resides.
Examples
• Shipment of server code to client – filling forms (reduce communication, no
need to pre-link stubs with client)
• Ship parts of client application to server instead of data from server to
client (e.g., databases)
BCA_DS_3_DN_NC(dineupane8@gmail.com) 76
The client first fetches the necessary
software then it invokes the server
Dynamic configurations of distributed
system
Client don’t need pre-installed
software –download on demand
For example
Code repository may contain driver
(for e.g JDBC) which client can fetches
to its site. Then client can initiate the
connection with the server
(eg. MYSQL Server, database
server)

BCA_DS_3_DN_NC(dineupane8@gmail.com) 78
Migrating models

BCA_DS_3_DN_NC(dineupane8@gmail.com) 79
Migrating models

BCA_DS_3_DN_NC(dineupane8@gmail.com) 80
Disadvantage of code migration
Security issue - blindly trusted the downloaded code

BCA_DS_3_DN_NC(dineupane8@gmail.com) 81

You might also like