1 / 34

Operating Systems

Operating Systems. Certificate Program in Software Development CSE-TC and CSIM, AIT September -- November, 2002. Objectives a review of OS processes and threads. 4. Processes and Threads (Ch. 4 S&G). chs 4 and 5 in the 6th ed. Overview. 1. Processes 2. Process Scheduling

komala
Download Presentation

Operating Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Operating Systems Certificate Program in Software DevelopmentCSE-TC and CSIM, AITSeptember -- November, 2002 • Objectives • a review of OS processes and threads 4. Processes and Threads(Ch. 4 S&G) chs 4 and 5 in the 6th ed.

  2. Overview 1. Processes 2. Process Scheduling 3. Operations on Processes 4. Cooperating Processes 5. Interprocess Communication (IPC) 6. Client/Server Communication continued

  3. 7. Threads 8. Thread Types 9. Multithreading Models 10. Pthreads

  4. 1. Processes • A process is an executing program. • Each process has its own program counter, stack pointer, address space. • Several processes may execute the same program, but they will have copies of the program data.

  5. Process Control Block (PCB) Fig. 4.2., p.91 process state next previous Process ID (PID) program counter registers memory structure open file table etc

  6. new terminated States of a Process Fig. 4.1, p.90 dispatch running exit ready interrupt eventcompleted waiting I/O eventor wait

  7. 2. Process Scheduling • Job scheduler (long-term scheduler) • select processes from storage to add to ready queue • CPU scheduler (short-term scheduler) • allocates a processor to a ready process

  8. ready queue Queuing Diagram Fig. 4.5, p.95;VUW CS 305 cpu I/O I/O queue I/O request time slice expired child executes join fork a child wait queue resource queue resourcerequest

  9. ready queue Medium-term Scheduling Fig. 4.6, p.96 swap in partially executedswapped out processes swap out end cpu I/O I/O queue I/O request

  10. Context Switching • Switching from one process to another • often takes tens of microseconds • Save executing process in its PCB • registers, program counter, state, … • Load/reload a process from its PCB continued

  11. 3. Operations on Processes • Process creation (fork) • parent/child relationship • child is usually a copy of its parent • usually they continue in parallel • Process termination • exit, abort, or kill • Suspension • internal (wait) or external (resource wait)

  12. 4. Cooperating Processes • Cooperating processes can affect each other • compare to independent processes • Advantages of process cooperation: • information sharing, (possible) computation speed-up, modularity, convenience

  13. Producer/Consumer • A producer process produces information that is consumed by a consumer process. • Many variations, e.g.: • unbounded-buffer • bounded-buffer shared memory buffer p c

  14. 5. Interprocess Communication (IPC) • IPC is allows processes to communicate and synchronize their actions. • A message-based approach: • processes communicate without shared vars • Two basic operations: • send(message) • receive(message)

  15. Messaging Issues • Message format • Unidirectional, bi-directional? • One-to-one, broadcasting, multicasting? • Direct, indirect links? • names, locating, mailboxes • Blocking (synchronous), non-blocking (asynchronous)? • Sender/receiver buffering

  16. 6. Client/Server Communication • A server is a program (or collection of cooperating programs) that provides services and/or manages resources on the behalf of other programs (its clients).

  17. Client/Server Environment clients LAN or WAN network Server Data

  18. Example • The ATM network: • the clients are the ATM machines • user interfaces;some simple application processing • the server is at the bank • most application processing;very large database of customer accounts

  19. Architectural Requirements • Reliable, robust communication between the clients and server. • Client/server cooperation • started by the client • Application processing is usually distributed between a client and the server. • Server controls services/data that the client accesses. • Server handles conflicting requests.

  20. Communication Types • Sockets • (TCP) sockets are like telephones • the client and server sockets are the endpoints of their communications link • Remote Procedure Calls (RPC) • the client ‘calls’ a function in the server • Remote Method Invocation (RMI) • the Java version of RPC

  21. 7. Threads • A thread shares its data and OS resources (e.g. open files) with its peer threads • Sharing and smaller size makes threads less expensive to create & context switch • sometimes called light-weight processes (LWPs)

  22. Threads Diagram Fig. 4.8, p.104 PC PC PC peer threads shared data

  23. Typical Thread States JUST_CREATED READY RUNNING BLOCKED

  24. Typical Thread Operations • fork() • creates a new thread sharing global structures • yield() • yields processor, enters ready queue • sleep() • yields processor, enters a wait queue • finish()

  25. Threading Issues • Semantics of fork() and exec() calls • Thread cancellation • Signal handling • Thread pools • Thread specific data

  26. 8. Thread Types • Kernel threads • useful for parallelising system features • e.g. Windows 9x/NT/2000, Linux • User threads • scheduled within a user process • not seen by the kernel • e.g. POSIX Pthreads, Solaris threads

  27. 9. Multithreading Models • Many-to-One • One-to-One • Many-to-Many

  28. 9.1 Many-to-One • Many user-level threads are mapped to a single kernel thread (or process). • Often used on systems that do not support kernel threads.

  29. 9.2. One-to-One • Each user-level thread maps to a kernel thread. • Examples • Windows 9x/NT/2000 • OS/2

  30. Windows 2000 • Each thread contains • a thread id • a register set • separate user and kernel stacks • a private data storage area

  31. 9.3. Many-to-Many Model • Allows many user level threads to be mapped to many kernel threads. • Examples: • Solaris 2 • Windows NT/2000 with the ThreadFiberpackage

  32. Solaris 2 Fig. 4.9, p.107 userthreads tasks lwp lwp lwp lwp lwp lwp kernelthreads kernel cpu cpu cpu

  33. 10. Pthreads • A POSIX standard API for thread creation and synchronization. • The API specifies the behavior of the thread library, but the implementation is up to the library developer. • Commonly found in UNIX, and variants.

More Related