1 / 30

Operating Systems Lecture 05: Processes (Chapter 3)

Operating Systems Lecture 05: Processes (Chapter 3). Anda Iamnitchi anda@cse.usf.edu. Concepts (review). Multiprogramming On a uniprocessor On a multiprocessor OS responsibilities A process is comprised of: Program code (possibly shared) Data Context Must be in memory in order to run

rona
Download Presentation

Operating Systems Lecture 05: Processes (Chapter 3)

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 SystemsLecture 05: Processes (Chapter 3) Anda Iamnitchi anda@cse.usf.edu

  2. Concepts (review) • Multiprogramming • On a uniprocessor • On a multiprocessor • OS responsibilities • A process is comprised of: • Program code (possibly shared) • Data • Context • Must be in memory in order to run • Why?

  3. Process Execution with Multiprogramming

  4. Trace from Processors point of view Timeout Timeout Timeout I/O

  5. What is needed for Context Switching?

  6. Process Attributes • Process identification • Process identifier • Parent process identifier • User identifier • Processor state information (contents of processor registers). • User-visible registers • Control and status registers: program counter, etc • Stack pointers • Process control information • Process state • Memory pointers • Interprocess communication, etc.

  7. Process Control Block

  8. CPU Switch 8

  9. Two-State Process Model • Process may be in one of two states • Running • Not-running

  10. Queuing Diagram Etc … processes moved by the dispatcher of the OS to the CPU then back to the queue until the task is competed

  11. Process Creation and Termination See tables 3.2 for more

  12. What’s Happening at Process Creation? • The OS: • Assigns a unique process identifier • Allocates space for the process • Initializes process control block • Sets up appropriate linkages • Creates or expand other data structures • Traditionally, the OS created all processes • But it can be useful to let a running process create another • This action is called process spawning • Parent Process is the original, creating, process • Child Process is the new process

  13. OS Control Tables

  14. Process Tables • To manage processes the OS needs to know details of the processes • Current state • Process ID • Location in memory • etc • Process control block • Process image is the collection of program, data, stack, and attributes

  15. Structure of Process Images in Virtual Memory

  16. A Tree of Processes in Solaris 16

  17. What’s Happening at Process Termination? • There must be some way that a process can indicate completion. • This indication may be: • A HALT instruction generating an interrupt alert to the OS. • A user action (e.g. log off, quitting an application) • A fault or error • Parent process terminating

  18. Five-State Process Model

  19. Using Two Queues

  20. Multiple Blocked Queues

  21. Suspended Processes • Problem: all processes in memory might be waiting for I/O (CPU much faster than I/O). • What to do? • Swapping • involves moving part of all of a process from main memory to disk • when none of the processes in main memory is in Ready, OS swaps one of the blocked processes out on to disk into a suspend queue

  22. One Suspend State

  23. Two Suspend States

  24. Modes of Execution • Most processors support at least two modes of execution • User mode • Less-privileged mode • User programs typically execute in this mode • System mode • More-privileged mode • Kernel of the operating system

  25. UNIX Process State Transition Diagram

  26. UNIX Process States

  27. Process Creation in Unix • Process creation is by means of the system call fork( ). • This causes the OS, in Kernel Mode, to: • Allocate a slot in the process table for the new process. • Assign a unique process ID to the child process. • Copy of process image of the parent, with the exception of any shared memory. • Increment the counters for any files owned by the parent, to reflect that an additional process now also owns those files. • Assign the child process to the Ready to Run state. • Returns the ID number of the child to the parent process, and a 0 value to the child process.

  28. After Creation • After creating the process the Kernel can do one of the following, as part of the dispatcher routine: • Stay in the parent process. • Transfer control to the child process • Transfer control to another process.

  29. Fork Example The following program contains no syntax errors. As it executes, it will create one or more processes. Show how processes are created and what is printed to the screen when this program executes.

  30. #include <stdio.h> main(){ int a, x, y, n; a=-5; n=1; x=-15; y=-20; a=fork(); if(a==0) y=fork(); while (n<3){ if(y==0) x=fork(); n++;} printf(“x=%d y=%d a=%d\n”, x, y, a);}

More Related