Processes Chapter 3 Processes 1 Introduction q A

  • Slides: 57
Download presentation
Processes Chapter 3 Processes 1

Processes Chapter 3 Processes 1

Introduction q. A process is a program in execution q For OS important issues

Introduction q. A process is a program in execution q For OS important issues are o Management of processes o Scheduling of processes q In dist systems, issues such as o Multithreading o Process/code migration o Software agents Chapter 3 Processes 2

Topics Covered q Threads q Clients q Servers q Code Migration q Software Agents

Topics Covered q Threads q Clients q Servers q Code Migration q Software Agents Chapter 3 Processes 3

Threads q Processes (not threads): OSs makes sure o Processes do not affect each

Threads q Processes (not threads): OSs makes sure o Processes do not affect each other, accidentally or intentionally (separation) o Processes not aware of each other (concurrency transparency) Costly to set up independent processes q Switching between processes is costly q o Must save state of current process o Must restore state of new process o Might also have to swap to disk Chapter 3 Processes 4

Threads Thread is like a (sub)process q But, OS does not provide concurrency transparency

Threads Thread is like a (sub)process q But, OS does not provide concurrency transparency between threads q For example, don’t protect data from access by other threads within a process q Plusses? q o Efficiency q Minuses? o More work for application developer Chapter 3 Processes 5

Threading Example q Spreadsheet o o program Change to one cell updates many cells

Threading Example q Spreadsheet o o program Change to one cell updates many cells Interface is one thread, update another Gives impression both are simultaneous Even better in multiprocessor system q Other examples? o Word processor q Distributed Chapter 3 Processes examples? 6

Interprocess Communication If separate processes, 3 context switches q If same process, but separate

Interprocess Communication If separate processes, 3 context switches q If same process, but separate threads, more efficient q Chapter 3 Processes 7

Thread Implementation q Two possible approaches o User-level threads all in user space o

Thread Implementation q Two possible approaches o User-level threads all in user space o Kernel-level threads kernel is involved q User-level threads o Plus: cheap to create/destroy threads o Plus: thread context switch is cheap o Minus: Blocking system call will block all threads in process (e. g. , blocking on I/O) q Kernel-level threads remove the “minus” o But thread context switching is more costly Chapter 3 Processes 8

Lightweight Processes User-level threads and… q Lightweight processes (LWPs) that act like kernel-level threads

Lightweight Processes User-level threads and… q Lightweight processes (LWPs) that act like kernel-level threads q LWPs take care of threads as needed q Plusses? q o Thread stuff is efficient (user-level) o Blocking system call will not suspend all threads (provided enough LWPs) o Apps need not be aware of LWPs o LWPs can execute on different processors Chapter 3 Processes 9

Threads and LWPs A bunch of LWPs hang around q LWPs grab threads as

Threads and LWPs A bunch of LWPs hang around q LWPs grab threads as needed q Chapter 3 Processes 10

Threads in Dist Systems q Advantage to threads in dist system o Can block

Threads in Dist Systems q Advantage to threads in dist system o Can block without stalling entire process q Multithreaded clients o Conceal communication delays o For example, a Web browser q Multithreaded servers o More benefit on server side than client o Process incoming requests and do local things o Without threading, could implement this as a “big finite-state machine” (saving state, etc. ) Chapter 3 Processes 11

Multithreaded Servers q Multithreaded server o dispatcher/worker model Chapter 3 Processes 12

Multithreaded Servers q Multithreaded server o dispatcher/worker model Chapter 3 Processes 12

Multithreaded Servers q Model Characteristics Threads Parallelism, blocking system calls Single-threaded process No parallelism,

Multithreaded Servers q Model Characteristics Threads Parallelism, blocking system calls Single-threaded process No parallelism, blocking system calls Finite-state machine Parallelism, nonblocking system calls Three ways to construct a server o Single thread process stalls o Finite state machine hard to program o Threads totally awesome, dude q Threads rule! Chapter 3 Processes 13

Threads: The Bottom Line q Consider RPC with blocking system call o Easy to

Threads: The Bottom Line q Consider RPC with blocking system call o Easy to program, but… o Inefficient without threads since… o No parallelism q W/O threads, finite state machine o Then obtain parallelism o But very painful to program q Threads provide o Sequential programming and parallel processes Chapter 3 Processes 14

Clients q Client interacts with user and server q UI is sometimes simple o

Clients q Client interacts with user and server q UI is sometimes simple o Cell phone q Sometimes UI is not-so-simple o X Window System Chapter 3 Processes 15

X Window System q. X Window System consists of o X kernel low level

X Window System q. X Window System consists of o X kernel low level interface for screen, mouse, etc. o Xlib to access X kernel o Window manager app that can manipulate screen o X protocol allows for X kernel and X app to reside on different machines o X terminals client using X protocol Chapter 3 Processes 16

X Window System q Organization Chapter 3 Processes of X Window System 17

X Window System q Organization Chapter 3 Processes of X Window System 17

Client-Side Transparency q Consider ATM and TV set-top box o For these, UI is

Client-Side Transparency q Consider ATM and TV set-top box o For these, UI is small part of client side o Lots of processing on client side, lots of communication from client side q Client-side transparency is possible q Server side transparency harder to achieve (performance issues) o And not so important Chapter 3 Processes 18

Client-Side Transparency q Access transparency o Client stub (middleware) q Location, migration, and relocation

Client-Side Transparency q Access transparency o Client stub (middleware) q Location, migration, and relocation transparency o Naming q Replication transparency o One approach is on next slide Chapter 3 Processes 19

Client-Side Transparency q Replication transparency o Client (stub) invokes object on all replicas o

Client-Side Transparency q Replication transparency o Client (stub) invokes object on all replicas o Collects responses and passes one result to client Chapter 3 Processes 20

Client-Side Transparency q Failure transparency o Client middleware repeatedly attempt to connect to server

Client-Side Transparency q Failure transparency o Client middleware repeatedly attempt to connect to server o Client middleware tries another server o Client provides cached result q Concurrency/persistence transparency o ? ? ? Chapter 3 Processes 21

Servers q Server a process implementing a service for a collection of clients o

Servers q Server a process implementing a service for a collection of clients o Server waits for incoming requests o Server services requests q Server can be iterative or concurrent o Iterative handles request, response o Concurrent passes request to another process/thread (fork a new process) Chapter 3 Processes 22

Servers q Requests o Port q How arrive at an endpoint does client know

Servers q Requests o Port q How arrive at an endpoint does client know endpoint? o Well-known o Some service to look it up q Superserver serves servers o Listens for a bunch of “servers” Chapter 3 Processes 23

Client-to-Server Binding a) b) Chapter 3 Processes Client-to-server binding using a daemon as in

Client-to-Server Binding a) b) Chapter 3 Processes Client-to-server binding using a daemon as in DCE Client-to-server binding using a superserver as in UNIX 24

Other Server Issues q How to interrupt server? o Break connection (common in Internet)

Other Server Issues q How to interrupt server? o Break connection (common in Internet) o Out of band data Stateless vs stateful q Stateless no memory of clients and can change its state without telling clients q o For example, a Web server (w/o cookies) q Stateful remembers its clients o For example, file server must remember who has file at any given time Chapter 3 Processes 25

Stateless vs Stateful q Stateless vs stateful server q What if server crashes… q

Stateless vs Stateful q Stateless vs stateful server q What if server crashes… q Stateless? o No problem, just restart q Stateful? o Big problems… q Security Chapter 3 Processes of stateless vs stateful? 26

Object Server q Server designed for dist objects o “a place where objects live”

Object Server q Server designed for dist objects o “a place where objects live” o Easy to change services on server q Read Section 3. 3. 2 Chapter 3 Processes 27

Code Migration q Code migration passing programs o Perhaps even while executing Expensive, so

Code Migration q Code migration passing programs o Perhaps even while executing Expensive, so why bother? q Consider process migration q o Move a process to another machine o Move process from heavily loaded machine o A form of load balancing q When is it worthwhile? o Not easy to calculate in heterogeneous network o Minimizing communication may be good reason Chapter 3 Processes 28

Code Migration q For example o Server manages a huge database o Spse client

Code Migration q For example o Server manages a huge database o Spse client needs to access and process lots of data o May save bandwidth by shipping process to the server q Other examples (wrt performance)? Chapter 3 Processes 29

Code Migration q Code migration might also increase flexibility q For example, it might

Code Migration q Code migration might also increase flexibility q For example, it might be possible to dynamically configure the system q Dynamically download client software o No need to pre-install software o Other benefits? o What about security? Chapter 3 Processes 30

Reason for Migrating Code q Dynamically configuring client o Client fetches necessary software o

Reason for Migrating Code q Dynamically configuring client o Client fetches necessary software o Then client contacts server Chapter 3 Processes 31

Models for Code Migration q Process consists of 3 segments o Code segment self

Models for Code Migration q Process consists of 3 segments o Code segment self explanatory o Resource segment external resources o Execution segment current state q Weak mobility migration of code segment and some initialization data o For example, Java applets o Simple, only requires code is portable o Execute in current process, or start new one Chapter 3 Processes 32

Models for Code Migration q Strong mobility migrate exe segment o Running process stopped,

Models for Code Migration q Strong mobility migrate exe segment o Running process stopped, moved to another machine, starts where left off o For example, D’Agents o Complex but powerful q Instead of moving the process, might clone the process o Then runs in parallel at client and server q Why? o Cloning improves transparency Chapter 3 Processes 33

Models for Code Migration Sender or receiver initiated? q Sender initiated q o Initiated

Models for Code Migration Sender or receiver initiated? q Sender initiated q o Initiated by machine where code resides o For example, uploading program to server o Other examples? q Receiver initiated o Initiated by target machine o For example, Java applets o Other examples? Chapter 3 Processes 34

Models for Code Migration q Receiver initiated client takes initiative o Code migrates to

Models for Code Migration q Receiver initiated client takes initiative o Code migrates to client o Done for performance reasons q Sender initiated server takes initiative o Code migrates to server o Probably want access to server data q Receiver initiated is o Simpler (why? ) o More secure (why? ) Chapter 3 Processes 35

Models for Code Migration q Alternatives for code migration Chapter 3 Processes 36

Models for Code Migration q Alternatives for code migration Chapter 3 Processes 36

Migration and Local Resources q What about resource segment? q Spse process is using

Migration and Local Resources q What about resource segment? q Spse process is using a specific port for communication o This info is in resource segment q If process migrates, gets a new port q But an absolute URL will not change o Also in resource segment Chapter 3 Processes 37

Migration and Local Resources 3 types of process-to-resource binding q Binding by identifier q

Migration and Local Resources 3 types of process-to-resource binding q Binding by identifier q o Known locally and remotely o For example, URL or IP address q Binding by value q Binding by type o Available locally and remotely, but location might be different o C or Java library o Only available locally o Local devices (printers, monitors, etc. ) Chapter 3 Processes 38

Migration and Local Resources 3 types of resource-to-machine bindings q Unattached resources q o

Migration and Local Resources 3 types of resource-to-machine bindings q Unattached resources q o Easy to move from one machine to another o Such as data files used by programs q Attached resources o Difficult to move from on machine to another o Such as database or entire website q Fixed resources o Cannot be moved o Such as local devices Chapter 3 Processes 39

Migration and Local Resources Resource-to machine binding Process-toresource binding q q By identifier By

Migration and Local Resources Resource-to machine binding Process-toresource binding q q By identifier By value By type Unattached Attached Fixed MV (or GR) CP ( or MV, GR) RB (or GR, CP) GR (or MV) GR (or CP) RB (or GR, CP) GR GR RB (or GR) GR establish global systemwide reference MV move the resource CP copy the file to the resource RB rebind process to locally available resource Chapter 3 Processes 40

Migration in Heterogeneous Systems Code executes on different platforms q Each platform must be

Migration in Heterogeneous Systems Code executes on different platforms q Each platform must be supported q Easier if limited to weak mobility q o Different code segments In strong mobility, difficult… q Restrict migration to certain points in code q o Such as a function call q Maintain machine independent stack o Migration stack Chapter 3 Processes 41

Migration in Heterogeneous Systems q q Maintaining a migration stack to support migration of

Migration in Heterogeneous Systems q q Maintaining a migration stack to support migration of an execution segment Can be done in C/C++ Chapter 3 Processes 42

Migration in Heterogeneous Systems q Migration in heterogeneous systems o Basic problem is similar

Migration in Heterogeneous Systems q Migration in heterogeneous systems o Basic problem is similar to portability q What is the solution for portability? o Virtual machine is one solution q So similar solution should work here Chapter 3 Processes 43

Code Migration in D'Agents q Middleware approach q Supports various forms of code migration

Code Migration in D'Agents q Middleware approach q Supports various forms of code migration q Read it! Chapter 3 Processes 44

Software Agents q So o o far Threads Clients Servers Mobility q And now

Software Agents q So o o far Threads Clients Servers Mobility q And now for something completely different… q Software agents Chapter 3 Processes 45

Software Agents q Software agents no precise definition o “Autonomous agents capable of performing

Software Agents q Software agents no precise definition o “Autonomous agents capable of performing a task in collaboration with other, possibly remote, agents” o “An autonomous process capable of reacting to, and initiating change in, its environment, possibly in collaboration with users and other agents” Able to act on its own (autonomous) q Able to cooperate with other agents q Able to take the initiative q Chapter 3 Processes 46

Software Agents q Collaborative agents o Agents that work together as part of multiagent

Software Agents q Collaborative agents o Agents that work together as part of multiagent system o Example: agents that arrange a meeting q Mobile agents o Able to move between machines o May require strong mobility o Example: to “police” the Internet Chapter 3 Processes 47

Software Agents q Interface agents o Assist users with one or more applications o

Software Agents q Interface agents o Assist users with one or more applications o Actively learns from its interactions o Example: agent that brings buyers and sellers together q Information agents o Manage info from many different sources o In distributed system, info is from physically distributed systems o Example: email agent to filter spam, others? Chapter 3 Processes 48

Software Agents Property Common to all agents? Description Autonomous Yes Can act on its

Software Agents Property Common to all agents? Description Autonomous Yes Can act on its own Reactive Yes Responds timely to changes in its environment Proactive Yes Initiates actions that affects its environment Communicative Yes Can exchange information with users and other agents Continuous No Has a relatively long lifespan Mobile No Can migrate from one site to another Adaptive No Capable of learning q Properties of software agents Chapter 3 Processes 49

Intelligent Agents q Foundation for Intelligent Physical Agents o FIPA Developing general model for

Intelligent Agents q Foundation for Intelligent Physical Agents o FIPA Developing general model for agents q Agents registered at agent platform q Platform provides basic services q o Create and delete agents o Locate agents (directory service) o Inter-agent communication facilities Chapter 3 Processes 50

FIPA Platform q q FIPA model for an agent platform Agent Communication Channel (ACC)

FIPA Platform q q FIPA model for an agent platform Agent Communication Channel (ACC) o Sending messages between platforms o Uses Internet Inter-ORB Protocol (IIOP) Chapter 9 Chapter 3 Processes 51

ACL q FIPA defines Agent Communication Language o Defines a “high level communication protocol

ACL q FIPA defines Agent Communication Language o Defines a “high level communication protocol between a collection of agents” o How does this differ from IIOP? q Separation between msg purpose and content o o Header states the msg purpose Format and language of content is left open Need enough info in header to interpret content Ontology: mapping of symbols to meanings Chapter 3 Processes 52

ACL Message purpose Description Message Content INFORM Inform that a given proposition is true

ACL Message purpose Description Message Content INFORM Inform that a given proposition is true Proposition QUERY-IF Query whether a given proposition is true Proposition QUERY-REF Query for a give object Expression CFP Ask for a proposal Proposal specifics PROPOSE Provide a proposal Proposal ACCEPT-PROPOSAL Tell that a given proposal is accepted Proposal ID REJECT-PROPOSAL Tell that a given proposal is rejected Proposal ID REQUEST Request that an action be performed Action specification SUBSCRIBE Subscribe to an information source Reference to source q Different “purposes” in FIPA ACL Chapter 3 Processes 53

ACL Example q q Field Value Purpose INFORM Sender max@http: //fanclub-beatrix. royalty-spotters. nl: 7239

ACL Example q q Field Value Purpose INFORM Sender max@http: //fanclub-beatrix. royalty-spotters. nl: 7239 Receiver elke@iiop: //royalty-watcher. uk: 5623 Language Prolog Ontology genealogy Content female(beatrix), parent(beatrix, juliana, bernhard) Sender INFORMs receiver of Dutch royal genealogy Ontology says that Prolog statements to be semantically interpreted as genealogy info Chapter 3 Processes 54

Summary q Threads o Sequential programming o Parallel processing q Clients o User interface

Summary q Threads o Sequential programming o Parallel processing q Clients o User interface o Distribution transparency Chapter 3 Processes 55

Summary q q Servers o o Efficiency more important than transparency Interactive or concurrent?

Summary q q Servers o o Efficiency more important than transparency Interactive or concurrent? Stateful or stateless? Object servers o o Performance and flexibility Strong mobility vs weak mobility Local resources? Heterogeneity/virtual machines Code migration Chapter 3 Processes 56

Summary q Software agents o Autonomous and cooperative o Agent communication language (ACL) o

Summary q Software agents o Autonomous and cooperative o Agent communication language (ACL) o Purpose vs content Chapter 3 Processes 57