Click here to load reader

Operating Systems: Processes, Threads, and Scheduling Ref: & Silberschatz, Gagne, & Galvin,

  • View
    234

  • Download
    2

Embed Size (px)

Text of Operating Systems: Processes, Threads, and Scheduling Ref: & Silberschatz, Gagne, &...

  • Operating Systems:Processes, Threads, and SchedulingRef: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

    Ref: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

  • ProcessesIn embedded systems, process management, including enabling processes to meet hard or soft deadlines, is of paramount importance. So we need to understand the important concepts in this area.

    Ref: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

    Ref: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

  • Process ConceptProcess a program in execution; process execution must progress in sequential fashion.A process includes:program counter stackdata sectionheapRef: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

    based on material at http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm

  • Process StateAs a process executes, it changes statenew: The process is being created.running: Instructions are being executed.waiting: The process is waiting for some event to occur.ready: The process is waiting to be assigned to a process.terminated: The process has finished execution.Ref: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

    based on material at http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm

  • Process Control Block (PCB)Information associated with each process.Process stateProgram counterCPU registersCPU scheduling informationMemory-management informationAccounting informationI/O status information

    Ref: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

    based on material at http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm

  • CPU Switch From Process to ProcessThis PCB is saved when a process is removed from the CPU and another process takes its place (context switch).Ref: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

    Ref: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

  • SchedulersLong-term scheduler (or job scheduler) selects which processes should be brought into the ready queue.

    Short-term scheduler (or CPU scheduler) selects which process should be executed next and allocates CPU.Ref: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

    Ref: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

  • Context SwitchWhen the CPU switches to another process, an interrupt occurs and a kernel routine runs to save the current context of the currently running process (PCB)The system must save the state of the old process and load the saved state for the new process.Context-switch time is overhead; the system does no useful work while switching.Time dependent on hardware support.Varies from 1 to 1000 microsecondsRef: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

    Ref: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

  • Process CreationParent process create children processes which, in turn, create other processes forming a tree of processes.Each process is assigned a unique process identifier (pid)Resource sharing--possible approaches:Parent and children share all resources.Children share subset of parents resources.Parent and child share no resources.Executionpossible approaches:Parent and children execute concurrently.Parent waits until some or all of its children terminate.

    Ref: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

    Ref: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

  • Process Creation (Cont.)Address spaceChild duplicate of parent (UNIX)Child has copy of parents address space Enables easy communication between the twoThe child process memory space is replaced with a new program which is then executed. Parent can wait for child to complete or create more processesChild has a program loaded into it directly (DEC VMS)Windows NT supports both modelsRef: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

    Ref: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

  • Process Creation (Cont.)UNIX examplefork() system call creates new process which has a copy of the address space of the original processSimplifies parent-child communicationBoth processes continue executionexeclp() system call used after a fork()to replace the process memory space with a new program.Loads a binary file into memory and starts executionParent can then create more children processes or issue a wait() system call to move itself off the ready queue until the child completesRef: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

    based on material at http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm

  • Process TerminationProcess executes last statement and asks the operating system to delete it by using the exit() system callProcess may return a status value to parent via wait()Process resources are deallocated by operating system.Parent may terminate execution of children processes abort() in UNIX or TerminateProcess() in Win32Child has exceeded allocated resources.Task assigned to child is no longer required.Parent is exiting.Some operating systems do not allow child to continue if its parent terminates - cascading termination.Ref: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

    Ref: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

  • Process TerminationIn UNIX, a process can be terminated via the exit system call. Parent can wait for termination of child by the wait system callwait returns the process identifier of a terminated child so that the parent can tell which child has terminatedIf a parent terminates, all children are assigned the init process as their new parentRef: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

    Ref: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

  • Cooperating ProcessesIndependent process cannot affect or be affected by the execution of another process.Cooperating process can affect or be affected by the execution of another processAdvantages of process cooperationInformation sharing Computation speed-up via parallel sub-tasksModularity by dividing system functions into separate processes Convenience - even an individual may want to edit, print and compile in parallelRef: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

    Ref: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

  • Cooperating ProcessesCooperating processes require an interprocess communication (IPC) mechanism to exchange data(a) Message passing useful for small amounts of dataeasier to implement than shared memoryrequires system calls and thus intervention of the kernel(b) Shared memorymaximum speed (speed of memory) and conveniencesystem calls required only to establish the shared memory regions; further I/O does not require the kernel

    Ref: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

    Ref: http://userhome.brooklyn.cuny.edu/irudowdky/OperatingSystems.htm & Silberschatz, Gagne, & Galvin, Operating Systems Concepts, 7th ed, Wiley (ch 1-3)

  • Producer-Consumer ProblemParadigm for cooperating processes, producer process produces information that is consumed by a consumer process.A shared buffer enables the producer and consumer to run concurrentlye.g., print program produces characters that are consumed by the print driverunbounded-

Search related