1 of 29

Chapter 3: Process-Concept

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition,

2 of 29

Chapter 3: Process-Concept

  • Process Concept
  • Process Scheduling
  • Interprocess Communication

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

3 of 29

Objectives

  • To introduce the notion of a process -- a program in execution, which forms the basis of all computation
  • To describe the various features of processes, including scheduling, creation and termination, and communication

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

4 of 29

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

5 of 29

Process Concept

  • An operating system executes a variety of programs:
    • In Batch system – jobs
    • In Time-shared systems – user programs or tasks
  • Textbook uses the terms job and process almost interchangeably (job = process)
  • Process – is a program loaded into memory and executing.
  • System consists of a collection of processes:
    • Operating system processes executing system code
    • User processes executing user code.
  • Process execution must progress in sequential fashion

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

6 of 29

The Process

  • Process includes:
    • Text section : which is program code
    • Stack- which contains temporary data (such as function parameters, return addresses, and local variables)
    • Data section: which contains global variables.
    • Program counter: the value of the program counter & contents of the processor’s registers.
    • Heap (some times): which is memory that is dynamically allocated during process run time.

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

7 of 29

Process VS Program

  • What is the difference between a process and program??
    • A program by itself is not a process
    • A program is a passive entity, such as a file containing a list of instructions stored on disk (executable file).
    • A process is an active entity, with a program counter specifying the next instruction to execute and a set of associated resources.
    • A program becomes a process when an executable file is loaded into memory.

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

8 of 29

Process State

  • As a process executes, it changes state
    • New: the process is being created
    • Running: instructions are being executed
    • Waiting: the process is waiting for some event to occur (e.g. An I/O completion).
    • Ready: the process is waiting to be assigned to a processor
    • Terminated: the process has finished execution

  • Only one process can be running on any processor at any instant. Many processes may be ready and waiting.

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

9 of 29

Diagram of Process State

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

10 of 29

Process Control Block (PCB)

  • Each process is represented in the operating system by a process control block (PCB)
  • PCB contains many information including :
      • Process state
      • Program counter
      • CPU registers
      • CPU scheduling information
        • e.g. a process priority
      • Memory-management information
      • Accounting information:
        • e.g . when the process was last run, how much CPU time it has used
      • I/O status information
        • It includes the list of I/O devices allocated to the process, a list of open files….etc .

Values of program counter

& CPU registers must be

saved when an interrupt occurs

to allow the process to be

continued correctly afterward

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

11 of 29

Process Control Block (PCB)

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

12 of 29

CPU Switch From Process to Process

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

13 of 29

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

14 of 29

Process Scheduling

  • Multiprogramming aims to have some process running at all times to maximize CPU utilization.
  • Time sharing aims to switch the CPU among processes so frequently user interact with each program while it is running.
  • Process scheduler selects an process (from a set of several available processes) for execution on the CPU.

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

15 of 29

Process Scheduling Queues

  • Job queue – set of all processes in the system
  • Ready queue – set of all processes residing in main memory, ready and waiting to execute
    • This queue is generally stored as a linked list.
  • Device queues – set of processes waiting for an I/O device
    • Each device has its own device queue

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

16 of 29

Process Scheduling Queues (cont.)

  • Processes migrate among the various queues:
    • A new process is initially put in the ready queue. It waits there until it is selected for execution. Once the process is allocated the CPU and is executing, one of several events could occur:
      • The process could issue an I/O request and then be placed in an I/O queue.
      • The process could create a new sub-process and wait for the sub-process’s termination.
      • The process could be removed forcibly from the CPU as a result of an interrupt, and be put back in the ready queue.

  • A process continues this cycle until it terminates, at which time it is removed from all queues and has its PCB and resources deallocated.

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

17 of 29

Representation of Process Scheduling

Queuing diagram

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

18 of 29

Schedulers

  • The operating system must select processes scheduling these queues. The selection process is carried out by the appropriate scheduler.
  • Long-term scheduler (or job scheduler) – selects which processes should be brought from mass-storage into RAM (to the ready queue )
  • Short-term scheduler (or CPU scheduler) – selects which process (from ready queue) should be executed next and allocates CPU

  • Short-term scheduler is invoked very frequently (milliseconds) ⇒ (must be fast)
  • Long-term scheduler is invoked very infrequently (seconds, minutes) ⇒ (may be slow)
    • The long-term scheduler controls the degree of multiprogramming

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

19 of 29

Schedulers (Cont)

  • Processes can be described as either:
    • I/O-bound process – spends more time doing I/O than computations, many short CPU intervals
    • CPU-bound process – spends more time doing computations; few very long CPU intervals.

  • The long-term scheduler must select a good process mix of I/O-bound and CPU-bound processes to improve total performance.
    • If all processes are I/O bound >>> the ready queue will almost always be empty, and the short-term scheduler will have little to do….(minimize CPU utilization)
    • If all processes are CPU bound >>> the I/O waiting queue will almost always be empty, devices will go unused….(minimize devices utilization)

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

20 of 29

Medium Term Scheduling

  • Medium Term Scheduling idea is :
    • Sometimes it can be advantageous to remove processes from RAM …….(swap out)
    • Later, the process can be reintroduced into RAM …….(swap in), and its execution can be continued where it left off.
    • This scheme is called swapping. The process is swapped out, and is later swapped in, by the medium-term scheduler.
      • Swapping may be necessary to improve the process mix or because a change in memory requirements has exceeded available memory, requiring memory to be freed up.

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

21 of 29

Addition of Medium Term Scheduling

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

22 of 29

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

23 of 29

Interprocess Communication

  • Processes within a system may be independent or cooperating
        • Independent processes
          • Cannot affect or be affected by the execution of another process.
        • Cooperating processes
          • Can affect or be affected by the execution of another process
  • Reasons (/advantages) for cooperating processes:
    • Information sharing : (e.g. shared file)
    • Computation speedup:
      • To make a particular task run faster, we must break it into subtasks, each of which will be executing in parallel with the others.
      • This can be achieved only if the computer has multiple processing elements (e.g. CPUs).
    • Modularity:
      • We may want to construct the system in a modular fashion (i.e. dividing the system functions into separate processes)
    • Convenience
      • An individual user may work on many tasks at the same time.

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

24 of 29

Interprocess Communication (Cont.)

  • Cooperating processes need interprocess communication (IPC)
  • IPC: mechanism that will allow cooperating processes to exchange data and information.
  • Two models of IPC:
    • Shared memory:
      • A region of memory that is shared by cooperating processes is established.
      • Processes can then exchange information by reading and writing data to the shared region.
    • Message passing
      • Communication takes place by means of messages exchanged between the cooperating processes..

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

25 of 29

Communications Models

Message passing

model

Shared memory model

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

26 of 29

Message passing VS Shared memory

  • Both models are common in operating systems, and many systems implement both.
  • Message passing:
    • Useful for exchanging smaller amounts of data, because no conflicts need be avoided.
    • Easier to implement than shared memory .
  • Shared memory
    • Shared memory is faster than message passing …..Because message passing systems requires more system calls (interrupts) .

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

27 of 29

End of Chapter 3

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition,

28 of 29

Some Helpful Notes

  • Some Terminologies :
    • Batch system :
      • System which Jobs are set up so they can be run to completion without human (/user) interaction.
      • This operating environment is termed as "batch processing" because the input data are collected into batches or sets of records and each batch is processed as a unit.
      • A program takes a set of data files as input, processes the data, and produces a set of output data files.
      • An example of a batch system is when a computer system processes telephone bills to a number of customers and then sends them out all at once rather than individually.

    • Program counter: is a register in a computer processor that contains the address (location) of the next instruction to be executed

    • Heap : is a partially sorted binary tree….(data structure)

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition

29 of 29

Some Helpful Notes

    • Modular programming is the process of subdividing a computer program into separate sub-programs.
      • Each sub-program accomplishes one function and contains all needed source code and variables.
      • Modular programming is a solution to the problem of very large programs that are difficult to debug and maintain.

3.*

Silberschatz, Galvin and Gagne ©2009

Operating System Concepts – 8th Edition