1 / 25

Operating Systems

Operating Systems. Dr. Jerry Shiao, Silicon Valley University. Processes. Overview Process Concepts Process is Program in Execution Process Control Blocks ( PCB ) Process State Operating System Responsibilities: Process Scheduling Short-Term, Long-Term, Medium-Term Schedulers

semah
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 Dr. Jerry Shiao, Silicon Valley University SILICON VALLEY UNIVERSITY CONFIDENTIAL

  2. Processes • Overview • Process Concepts • Process is Program in Execution • Process Control Blocks ( PCB ) • Process State • Operating System Responsibilities: • Process Scheduling • Short-Term, Long-Term, Medium-Term Schedulers • Operations on Process • Process Creation / Termination • InterProcess Communication • Shared-Memory Systems • Message-Passing Systems • Communication in Client-Server Systems • Sockets • Remote Procedure Calls • Pipes SILICON VALLEY UNIVERSITY CONFIDENTIAL

  3. Processes • Process Concept • Process is a unit of work in a Time-Sharing System. • Process contains: • Text Section – Program code. • CPU Program Counter • CPU Registers • Stack – Temporary data ( function parameters, return addresses, local variables ). • Data Section – Global variables. • Heap – Dynamically allocated memory during execution. Max Stack Process in Memory Heap Data Text 0 SILICON VALLEY UNIVERSITY CONFIDENTIAL

  4. Processes • Process Concept • Process State • New – Process is created. • Running – Instructions are being executed. • Waiting – Process is waiting for some event ( I/O or signal ). • Ready – Process is waiting to be assigned to CPU. • Terminated – Process finished execution. New Terminated Admitted Exit Interrupt Ready Running Scheduler Dispatch I/O or Event Completion I/O or Event Wait Waiting SILICON VALLEY UNIVERSITY CONFIDENTIAL

  5. Processes • Process Concept • Process Control Block ( PCB ) • Process State: • New/Ready/Running/Waiting/Terminated • Program Counter: • Address of instruction to be executed. • CPU Registers: • Accumulators, index registers, stack pointers, general purpose. • CPU-Scheduling Information: • Process priority, pointer so scheduling queues. • Memory-Management Information: • Base and limit registers, page tables. • Accounting Information: • Amount of CPU time used, accounting numbers. • I/O Status Information: • List of I/O devices allocated to the process, list of open files. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  6. Processes • Process Concept • Threads • Process supporting multiple threads of execution. Process P0 Operating System Process P1 Executing Interrupt or System Call Save State into PCB0 . . . Reload State From PCB1 Executing Interrupt or System Call Save State into PCB1 . . . Executing Reload State From PCB0 SILICON VALLEY UNIVERSITY CONFIDENTIAL

  7. Processes • Process Scheduling • Scheduling Queues • Objectives: • For Multi-Programming, maximize CPU utilization. • For Time Sharing, switch CPU amount processes • Ready Queue: • Processes waiting to execute. • Device Queues: • Processes waiting for I/O Request to complete. PCB 0 PCB 2 NULL Ready Queue Head Head Head Tail Registers Registers . . . . . . PCB 3 Disk Unit 0 Head Head NULL Tail Registers . . . SILICON VALLEY UNIVERSITY CONFIDENTIAL

  8. Processes • Process Scheduling • Scheduling Queues • Queuing Diagram Process Scheduled CPU Ready Queue I / O I/O Request I/O Queue Time Slice Expired Child Executes Fork a Child Interrupt Occurs Wait for an Interrupt SILICON VALLEY UNIVERSITY CONFIDENTIAL

  9. Processes • Process Scheduling • Schedulers • Short-Term Scheduler • Selects a new process for the CPU frequently ( every 100 milliseconds ). • I/O bound processes - Interactive processes are I/O-bound, spending a lot of time waiting for I/O operations. • Interactive processes waiting for human input. • Response time must be quick (latency 50-150ms). • Command shells, text editors, graphical applications, mouse and keyboard processes. • Time-Sharing systems, UNIX and Microsoft Windows. • Long-Term Scheduler • Selects a new process less frequently ( order of minutes ). • Controls the degree of multi-programming ( number of processes in memory ). Ideally, new process starts as a process exits. • CPU bound processe - Batch processes are CPU-bound, heavily ultilize CPU time for computations. • Batch processes typically executing in background, i.e. compilers, database search engines, and scientific computiations. • No user interactions. • Batch systems, IBM mainframe systems. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  10. Processes • Process Scheduling • Schedulers • Medium-Term Scheduler • Time-Sharing systems needs combination of short and long term schedulers. • Reduce the degree of mult-programming ( remove processes from memory ) and contention for CPU by swapping processes out to disk. • Overcommitted available memory. • Process swapped in later when process mix is more favorable. Swap In Partially Executed Swapped-Out Processes Swap Out Process Terminate Process To Be Scheduled Scheduled CPU Ready Queue I/O I/O Waiting Queues SILICON VALLEY UNIVERSITY CONFIDENTIAL

  11. Processes • Process Scheduling • Context Switch • Interrupts switch CPU from executing process to Kernel process. • Need to save and restore interrupted process. • PCB contains context of the process • CPU Registers • Process State • Memory-Management Information • Switch the CPU to another process • All Overhead, speed depends on: • Memory Speed • Number of registers • Hardware assist • Single instruction to load or restore all registers . • CPU contains multiple sets of registers ( Sun UltraSPARC ). • Preserve and restore process Page Table. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  12. Processes • Operations on Processes • Process Creation • Process ( parent process ) creates new processes ( child process ). • Process Identifier ( PID ) uniquely identifies a process. • UNIX: fork ( ) System Call. • Created process used to execute another program in parallel ( parent process continue to execute ) or parent program will wait for child process to complete. • exec ( ) system call loads binary image into memory to execute, but loaded over the process that called exec ( ). fork( ) Parent wait( ) Parent Resumes Child exec(‘cmd’ ) exit( ) SILICON VALLEY UNIVERSITY CONFIDENTIAL

  13. Processes • Operations on Processes • Process Creation • Windows: CreateProcess ( ) System Call. • Similar to UNIX fork( ), but CreateProcess( ) is passed, as a parameter, the program to load and execute. • Process Termination • Child exceeded resource usage ( shared with parent and other child processes ). • Child’s program execution not needed. • Parent termination. WaitForSingleObject( ) CreateProcess ( ) Parent Parent Resumes Child ‘cmd’ exit( ) SILICON VALLEY UNIVERSITY CONFIDENTIAL

  14. Processes • Interprocess Communication • Process is independent if it cannot affect or be affected by other processes in the system. • Process is cooperating if it can affect or be affected by other processes in the system. • Concurrent access to shared data. • Computational speedup with subtasks. • Modularity in system design with separate processes or threads. • Convenience with subtasks. • Cooperating Process and InterProcess Communcation ( IPC ) • Shared-Memory Systems • Region of memory shared between processes to exchange messages and data. • Message Passing Systems • Messages exchanged through System Calls to the Kernel. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  15. Processes Message Passing Shared memory • Interprocess Communication Process A Process A M Process B Process A Shared M Kernel Kernel M SILICON VALLEY UNIVERSITY CONFIDENTIAL

  16. Processes • Interprocess Communication • Shared-Memory Systems • Shared Region exists in the address space of the process creating the shared-memory segment. • Processes must handle synchronizing shared-memory segment read and write. • Cooperating Processes: Producer – Consumer • Producer ( Server ): Produces information • Web Server creates and sends HTML files and images. • Consumer ( Client ): Consumes information • Web Browser reads the HTML files and images. • Producer – Consumer relationship between processes represented by shared-memory segment. • Shared-memory segment circular buffer and in / out pointers. • Producer process writes into circular buffer moving in pointer. • Consumer process reads from circular buffer moving out pointer. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  17. Processes • Interprocess Communication • Shared-Memory Systems • POSIX API for Shared Memory • Create shared-memory segment segment_id = shmget( segment_id, size, S_IRUSR | S_IWUSR ) segment_id = IPC_PRIVATE or ftok(“<filename>”, id) IPC_PRIVATE: New shared memory segment is created. size: In bytes of shared-memory segment. S_IRUSR | S_IWUSR: Read and write to shared-memory segment. • Access shared-memory segment shared_memory = (char *) shmat( segment_id, NULL, 0 ) shared_memory: Pointer to shared-memory segment. segment_id: Shared-memory segment identifier. NULL: Operating System selects where to attach the shared-memory. 0: Attach shared-memory in read / write mode. • Remove shared-memory segment shmdt ( shared_memory ) shared memory: Detach shared-memory region. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  18. Processes • Interprocess Communication • Message-Passing System • Operating System provides message-passing facility for cooperating processes. • Communication Link for send ( ) / receive ( ) operations: • How to refer to the process • Direct Communication • Explicitly name the recipient or sender establishes link automatically: • send ( <processID1>, message ), receive ( <processID2>, message ). • Symmetry addressing ( recipient and sender names must be known). • Asymmetry addressing ( Sender name known, recipient receives processID ). • send ( <processID1>, message ), receive ( <id>, message ). • Indirect Communication • Messages sent to and received from mailboxes or ports. • send ( <mailbox ID>, message ), receive ( <mailboxID>, message ) • Process has number of different links, each link corresponding to one mailbox. • Mailbox Process Owned: Dependency, unique owner. • Mailbox Operating System Owned: Independent, not attached to a process. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  19. Processes • Interprocess Communication • Message-Passing System • Communication Link for send ( ) / receive ( ) operations: • Synchronous Communications • Blocking Send: Sending process blocked until receive by process or mailbox. • Blocking Receive: Receiving process blocks until message received. • Asynchronous Communications • NonBlocking Send: Sending process not blocked. • NonBlocking Receive: Receiving process receives message or NULL. • Buffering • Messages exchanged reside in queue. • Zero Capacity: Queue has depth of zero. Sender must block until the recipient receives the message. • Bounded Capacity: Queue has n depth. Sender must block when the queue is full. • Unbounded Capacity: Queue has infinite depth. Sender never blocks. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  20. Processes • Client-Server System Communications • Sockets • Endpoints for communication. • Network IP address: port uniquely identifies connection • Port identifies the services to handle the request. • Port 23 = Telnet, Port 21 = FTP, Port 80 = HTTP. • Ports below 1024 are well-known for standard services. • Structure of message imposed by the client and server. Client: Web Browser Server: Web Server Dest=192.168.1.100 : 80 Src = 192.168.1.10 : 1625 Dest = 192.168.1.10 : 1625 Src = 192.168.1.100 : 80 SILICON VALLEY UNIVERSITY CONFIDENTIAL

  21. Processes • Client-Server System Communications • Remote Procedure Calls ( RPC ) • Abstract procedure-call mechanism to use between computer systems over a network connection. • Network IP address: RPC port uniquely identifies RPC program • RPC Port: • Statically defined RPC port number. • A daemon (program) at fixed port number that returns the RPC port number. Client: Send command in RPC message. Server: Process command in RPC message. Dest=192.168.1.100 : <RPC port> Src = 192.168.1.10 : 1625 Dest = 192.168.1.10 : 1625 Src = 192.168.1.100 : <RPC port> SILICON VALLEY UNIVERSITY CONFIDENTIAL

  22. Processes Client Message Server User calls Kernel to send RPC message to procedure X. • Client-Server System Communications Kernel sends message to MM to find port number. From: Client To: Server, Port: MM Re: Address for RPC X MM (MatchMaker) receives message, looks up answer. Kernel places port P in user RPC message. From: Server To: Client, Port: Kernel Re: RPC X Port: P Matchmaker replies to client with port P. Kernel sends RPC. From: Client To: Server, Port: P < contents > Daemon listening to port P receives message. Kernel receives reply, passes it to user. From: RPC, Port: P To: Client, Port: Kernel < output > Daemon processes request and process send output. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  23. Processes • Client-Server System Communications • Pipes • Conduit allowing two processes to communicate • Ordindary Pipes • Unidirectional, one-way communication. • Two-way communication require two pipes. • Parent-Child process relationship. • UNIX treats pipes as special files, requiring file descriptors. • pipe ( int fd [ ] ) command creates two file descriptors. • fd [ 0 ] is the read-end of the pipe. • fd p 1 ] is the write-end of the pipe. • Use standard read ( ) and write ( ) system calls. Parent fd(0) fd(1) Child fd(0) fd(1) Pipe SILICON VALLEY UNIVERSITY CONFIDENTIAL

  24. Processes • Client-Server System Communications • Pipes • Named Pipes • Bidirectional, but only half-duplex is permitted. • No Parent-Child process relationship. • Named pipes continue to exist after processes exits. • UNIX treats pipes as special FIFO files, requiring file descriptors. • mkfifo ( char *pathname ) command creates file. • Use standard open ( ) to get file descriptor and then use read ( ) and write ( ) system calls. • Both sides of fifo file must be opened, else one side blocks on open until another process opens the fifo file. • Processes must reside on same computer system. • Windows bidirectional, full-duplex permitted. • Processes can reside on the same or different computer systems. • CreateNamedPipe ( ) creates the named pipe. • ConnectNamedPipe ( ) connects to named pipe. • ReadFile() and WriteFile() used to manipulate the named pipe. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  25. Processes • Summary • Process is a Unit of Work in the Operating System. • System and User Processes Execute Concurrently with Operating System Multiplexing CPU Between Processes. • Operating System Placed Processes in Queues. • Two major classes of queues: I/O Request Queue and Ready Queue. • Scheduling the Queues: • Long-Term Scheduler, Short-Term Scheduler, Medium-Term Scheduler. • Parent / Child Process • Executes Concurrent or Parent Waits for Child Terminate. • Inter-Process Communication • Shared Memory and Message Passing • Client-Server Systems • Sockets, Remote Procedure Calls (RPC), Pipes (Ordinary and Named) SILICON VALLEY UNIVERSITY CONFIDENTIAL

More Related