Lecture 4 Multiprogramming and Time-sharing Multi-task

Section 1 Process and Process Model



Yong Xiang, Yu Chen, Guoliang Li, Ju Ren



Spring 2023

Outline

1. Multiprogramming and Cooperative Scheduling

  1. Time-sharing Multi-task and Preemptive Scheduling
  2. The Concept of Process
  3. Process Model

History

The widespread use of OS began during the transition from mainframes to minicomputers.

  • OS/360 is a multiprogramming batch OS in the mainframe (System/360) era
  • PDP series minicomputers from DEC
  • Many companies may have their own computers
  • Multiprogramming becomes common

Multiprogramming

  • Multiple executable programs in the memory
  • The programs share the processor
Job
  • One-time execution process of an application

Terms appeared in history: Job, Multiprogramming

  • Job and Multiprogramming are concepts used by IBM for multiprogramming

Cooperative scheduling

  • Executables program voluntarily relinquish the processor
  • OS does not interrupt the running program
  • OS is responsible for selecting the next program to take the processor for execution

Outline

  1. Multiprogramming and Cooperative Scheduling

2. Time-sharing Multi-task and Preemptive Scheduling

  1. The Concept of Process
  2. Process Model

History

The widespread use of minicomputers led to a demand for time-sharing and multi-task capabilities, resulting in the development of time-sharing multi-user OS.

  • Widely use of DEC's PDP and VAX minicomputers
  • DEC's VMX operating system
  • MIT's CTSS operating system
  • AT&T's UNIX operating system

Time-sharing Multi-task from user's perspective

Time-sharing Multi-task: from user's perspective

  • Multiple executable programs residing in memory
  • Each executable program takes the processor in a time-sharing way
  • The OS allocates CPU to each executable program by time slices
  • Process: one-time execution process of the application

Time-sharing Multi-task from the perspective of OS

  • Process: A dynamic execution process of a program with certain independent functions on a data collection. Also known as Task.
  • Process Switching: switch from the process corresponding to one application to the process corresponding to another application.

Job, Task and Process

Terms appeared in history: Job, Task, Process

  • Task and Process are concepts proposed by Multics and UNIX, respectively, for time-sharing multi-task
  • A process is one-time execution process of an application. In OS context, task and process are the same meaning
  • A job (goal) is a whole formed by a group of related program execution processes (processes, tasks) for the same goal

Reference: Difference between Job, Task and Process

Preemptive Scheduling

  • Process passively relinquishes processor
  • The process uses the processor in turn according to time slice, which is a "pause-continue" execution process
  • Based on the clock interrupt mechanism of hardware, OS can interrupt the running program at any time
  • The OS is responsible for selecting the next program to take the processor for execution

Outline

  1. Multiprogramming and Cooperative Scheduling
  2. Time-sharing Multi-task and Preemptive Scheduling

3. The Concept of Process

  1. Process Model

Process Switching

Process Features

  • Dynamic
    • Execution starts --> Pause --> Continue --> Execution ends
  • Concurrency
    • Multiple processes are executing during a time period
  • Limited independence
    • Processes do not need to be aware of each other's existence in the system

Composition of Process and Program

Composition of Process and Program

Relationship between Task (Process) and Program

  • A task is an abstraction of a program in the execution of OS

    • program = file (static & executable)
    • task = program in execution = program + execution status
  • Multiple executions of the same program lead to different tasks

    • E.g., multiple executions of the command "ls" lead to multiple tasks
  • Resources required for task execution

    • Memory: store code and data
    • CPU: execute instructions

Differences between Task (Process) and Program

  • Tasks are dynamic, programs are static
    • A program is a collection of ordered codes
    • A task is the execution of a program
  • Tasks are temporary, programs are permanent
    • A task is a state-changing process
    • Programs can be saved permanently
  • Tasks and programs have different compositions
    • The task consists of program codes, data and process control blocks

Process Status

A process contains all status information about a running program

  • Control Flow for task execution
    • Code content and code execution location (code segment)
  • Data accessed by the task
    • Memory read and written by tasks (heap, stack, data segment)
    • Registers read and written by tasks
      • general-purpose registers

Process Status

A process contains all status information about a running program

  • OS manages the data related to the task (task context )
    • General purpose registers required for task switching
    • Status registers required for task switching (PC, etc.)
    • Other information: the stack address of the task, etc.
    • Other resources: …

Task Control Block (TCB)

The core data structure of OS for managing tasks, also known as process control block (PCB)

  • OS manages and controls the information used by the process
  • OS uses TCB to describe the basic information and changing status of the process
  • TCB is the only symbol for a process
  • Each task has a corresponding TCB in OS

Process Control Block Managed by OS

Outline

  1. Multiprogramming and Cooperative Scheduling
  2. Time-sharing Multi-task and Preemptive Scheduling
  3. The Concept of Process

4. Process Model

Process State: Created and Ready

  • Created --> Ready
    • When was it created?
    • How to create?

Process State: Running

  • Created --> Ready --> Running
    • The kernel selects a ready task
    • How to run?

Process State: Waiting

  • Created --> Ready --> Running --> Waiting
    • The reason why the task enters the waiting status
      • Itself
      • The outside world

Process State Transition: Waking up

  • Created --> Ready --> Running --> Waiting --> Waking up
    • The reason for waking up the task
      • Self: wake up naturally?
      • Outside: be Woke up?

Process State Transition: Preempted

  • Created --> Ready --> Running --> Preempted
    • Why is the task preempted?

Process State: Exited

  • Created --> Ready --> Running --> ...... --> Exited
    • Why did the task exit?
      • Voluntary?
      • Forced?

Three-State Process Model

Process State Transition and System Call

  • Created --> Ready --> Running --> ...... --> Exited
  • Preempted, waiting, waking up

What system calls are involved?

  • exit, sleep
  • ...

Process State Transition and Process Switching

  • Created --> Ready --> Running --> ...... --> Exited
  • Preempted, waiting, waking up

During the lifecycle of a task, when does a task switch occur?

Process Switching

More powerful features that need to be developed: - Stronger isolation, collaboration between tasks...