PPT01 - Operating System - Process
PPT01 - Operating System - Process
Week 1
Session 2
Process
Sub Topics
• What is a Process?
• Process States
• Process Description
• Process Control
• Execution of the Operating System
• UNIX SVR4 Process Management
Acknowledgement
Image(s)
Area Chapter 3
Learning Objectives
At the end of this lecture, students are able to:
• LO 1: Describe each of the components of the Operating
Systems and their relationship.
What is a process?
Process
• A program in execution
• An instance of a program running on a computer
• The entity that can be assigned to and executed on a
processor
• A unit of activity characterized by the execution of a
sequence of instructions,
• a current state, and an associated set of system resources
Process Characteristic
• A unique process identifier
• State
• Priority
• Program Counter
• Memory pointers
• Context Data
• I/O status information
• Accounting information
Process Control Block (1)
• PCB is a data structure to store information
about processes
– Process identification
• Identifiers
– Numeric identifiers that may be stored with the process control
block include
– Identifier of this process
– Identifier of the process that created this process (parent process)
– User identifier
Process Control Block (2)
– Processor State Information
• User-Visible Registers
– A user-visible register is one that may be referenced by
means of the machine language that the processor
executes. Typically, there are from 8 to 32 of these registers,
although some RISC implementations have over 100.
Process Control Block (3)
• Processor State Information
– Control and Status Registers
These are a variety of processor registers that are employed to
control the operation of the processor. These include
• •Program counter: Contains the address of the next instruction
to be fetched
• •Condition codes: Result of the most recent arithmetic or logical
operation (e.g., sign, zero, carry, equal, overflow)
•Status information: Includes interrupt enabled/disabled flags,
execution mode
Process Control Block (4)
• Processor State Information
– Stack Pointers
• Each process has one or more last-in-first-
out (LIFO) system stacks associated with it.
A stack is used to store parameters and
calling addresses for procedure and system
calls. The stack pointer points to the top of
the stack.
Process Control Block (5)
• Process Control Information
– Scheduling and State Information
This is information that is needed by the operating system to
perform its scheduling function. Typical items of information:
•Process state: defines the readiness of the process to be
scheduled for execution (e.g., running, ready, waiting, halted).
• •Priority: One or more fields may be used to describe the scheduling
priority of the process. In some systems, several values are required
(e.g., default, current, highest-allowable)
• •Scheduling-related information: This will depend on the scheduling
algorithm used. Examples are the amount of time that the process has
been waiting and the amount of time that the process executed the
last time it was running.
•Event: Identity of event the process is awaiting before it can be
resumed
Process state
Two State Process Model
Process Creation
Process Termination
Process Termination
Reason for Process switch
• Clock interrupt
– process has executed for the maximum allowable time slice
• I/O interrupt
• Memory fault
– memory address is in virtual memory so it must be brought into
main memory
• Trap
– error occurred
– may cause process to be moved to Exit state
• Supervisor call
– such as file open
Five State Process Model
Process Model with one
suspend state
Process Model with two
suspend state
Process description
Process Description
Operating System Control
Structures
Process Control
Structures
• Process Location
Process Control
Structures
• Process Attribute
– Process identification
– Processor state information
– Processs control information
Process control
Modes of Execution
• User mode
– Less-privileged mode
– User programs typically execute in this mode
• System mode, control mode, or kernel mode
– More-privileged mode
– Kernel of the operating system
Process creation
• Assign a unique process identifier to the new
process.
• Allocate space for the process.
• Initialiaze the process control block.
• Set the appropriate lingkages.
• Create or expand other data structures.
Process Switching
• When to Switch Process
• Clock Interrupt
• I/O interrupt
• Memory Fault
Mechanism for interrupt the execution of a process
Process Switching
• Mode Switching
– It sets the program counter to the starting
address of anProcess
interrupt-handler
Switching
program.
– It switches from user mode to kernel mode so
the interrupt processing code may include
privileged insctructions.
Process Switching
• Change of Process State
– Save the context of processor, including program counter and other
registers.
– Update the process control block of the process that is currently in the
Running state.
– Move the process control block of this process to the appropriate
queue.
– Select another process for execution.
– Update the control block of the process selected.
– Update memory management data structures.
– Restore the context of the processor to that wich existed at the time
the selected process was last switched out of the Running state, by
loading in previous values of the program counter and other registers.
Execution of the
operating system
Execution of the OS
• Nonprocess Kernel
Execution of the OS
Source:
http://www.csl.mtu.e
du/cs4411.ck/www/
NOTES/process/fork/
create.html
fork()
Source: http://www.csl.mtu.edu/cs4411.ck/www/NOTES/process/fork/create.html
Create a process using Java
API
Source: Operating Systems Concepts with Java 8ed, Silberschatz and Gagne
system()
• Executes a command from within a program
• Much as if the command had been typed into a shell
• Creates a subprocess running the standard Bourne shell
• (/bin/sh) and hands the command to that shell for
• execution; subject to the features, limitations and security
of
• the shell; on most GNU/Linux systems, pointing to bash
Running command from Java
import java.io.*;
public class Discfree {
if (System.getProperty("os.name").equals("Linux")) {
Command = new String[1];
Command[0] = "df";
}
if (Command == null) {
System.out.print("Can't find free space on ");
System.out.println(System.getProperty("os.name"));
System.exit(1);
}
Operating Systems Concepts 8th ed with Java, Silberschatz, Galvin and Gagne
Running command from Java
Process Findspace = Runtime.getRuntime().exec(Command);
String line;
while ((line = Resultset.readLine()) != null) {
System.out.println(line);
}
}
}
Operating Systems Concepts 8th ed with Java, Silberschatz, Galvin and Gagne
Summary
• The principal function of the OS is to create, manage, and
terminate process.
• To perform its process managemenr functions, the OS
maintanins description of each process, or process image,
which includes the address space within which the process
executes, and process control block.
• During, its lifetime, a process, moves among a number of
states, are Reay, Running, and Blocked.
• A running process is interrupted either by an interrupt,
which is an event that occurs outside the process and that is
recognized by the processor, or by executing a supervisor
call to the OS.
Other References