Transcript Processes

Processes
Chapter 3
Processes in Distributed Systems
•
Processes and threads
–
–
•
Threads in distributed systems
–
•
Introduction to threads
Distinction between threads and processes
Clients/servers
Code migration
–
–
Motivation and models
Migration in heterogeneous systems
Processes
• Virtual processors
– Created by OS to execute a program
– Process table to keep track of virtual processors
• Process is a program in execution
– Executed on one of the virtual processors
• Operating systems ensure that processes are
independent and transparent
– Do not affect each other’s correctness
– Resource sharing is transparent
• Address space
Costs of Processes
• Processes are costly
• Creating a process requires creation of an entire
new address space
– Initializing memory segment, copying instructions to
text segment, initializing stack
• Switching b/w processes is costly as well
– Saving CPU context, modify registers of the memory
management unit, TLBs, swapping processes (if
number of processors are larger than what can fit in
main memory)
Threads
• Similar to a process
– Perceived as execution of (a part of) program
– Information maintained for sharing CPU is minimal
• Context of threads is captured by CPU context
– May be a little more information is needed for
management (like locks)
• Very little overheads
– Thread switching is easy
• Can provide performance gains
Threads in Non-Distributed Systems
• With processes a blocking system call blocks the
entire process
– Interactive programs like spreadsheets
– Computations cannot proceed while waiting on user
inputs or vice-versa
– Having two threads can solve problems
• Parallel programs
– Multiple threads, single address space
• Cooperating programs need to communicate
– IPCs are costly
Drawbacks of IPCs
• Needs kernel intervention (due to separate address
spaces)
• Multiple context switches
• Context switches are costly (changing MMU, flushing
TLB)
Implementing Threads
• Implemented as package
– Creation, destruction, synchronization
• Simpler approach – User level thread library
– All thread management is done at user level
– Kernel not even that there are multiple threads
• Thread creation, destruction and context switching
are cheap
– Creating stack
– Saving registers
• Drawback – Blocking system call blocks entire
process
Lightweight Process
• A hybrid approach
• Lightweight process runs in context of single
process
• Reside in kernel
• System also offers user-level threads
– All operations occur in user mode
• Thread package can be shared by multiple LWPs
• LWP is created by kernel and given its own stack
Light-Weight Process
LWPs Continued
• LWP has a scheduling routine and searches for a thread
to execute
– Thread pool
• Context switching to a thread if found
• On mutex, context switching happens if a runnable thread
is found
– LWP need not be informed
• LWP context switching happens on a blocking system
call
• Several advantages
– Cheap, will not block entire process, extends to multiprocessing
environment