0% found this document useful (0 votes)
87 views53 pages

PPT01 - Operating System - Process

The document discusses processes in operating systems. It defines a process as a program in execution that has a unique process identifier, state, and set of resources. Process information is stored in a process control block that includes identification, processor state, and scheduling data. It describes process states like running and ready. The document focuses on UNIX process management, discussing process creation using fork(), process state transitions, and how the operating system handles forking a new process from an existing parent process.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views53 pages

PPT01 - Operating System - Process

The document discusses processes in operating systems. It defines a process as a program in execution that has a unique process identifier, state, and set of resources. Process information is stored in a process control block that includes identification, processor state, and scheduling data. It describes process states like running and ready. The document focuses on UNIX process management, discussing process creation using fork(), process state transitions, and how the operating system handles forking a new process from an existing parent process.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 53

COMP6600 – Operating System

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

These slides have been adapted from:

Stallings, W. (2018). Operating Systems:


Internals and Design Principles. 9th.
ISBN: 978-0-13-467095-9

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

• Execution within User Process


Execution of the OS
• Process-Based Operating System
– Major kernel functions are separate process
– Process switching code is outside of the process.
– Modular structure implies easier to modify of the
operating system.
– Useful in multi-processor where certain processors can
be dedicated to certain OS operations.
UNIx SVR4 PROCESS
MANAGEMENT
UNIX Process State
UNIX Process State Transition
Diagram
Process Description
• UNIX Process Image
– A process in UNIX is a rather complex set of data
structures that provde the OS with all of the
information necessary to manage and dispatch
processes.
– The elements of process image, which are
organized into three parts:
• user level context,
• register context,
• system-level context.
Process Description
• UNIX Process Table Entry
– The process table entry contains process control
information tha is accessible to the kernel at all times.
• UNIX U Area
• The user area or U area, contains additional process
control information tha is needed by the kernel when it
is executing in the context of this process.
• It is also used whe paging process to and from
memory.
• Distinction between UNIX Process Table
Entry and U Area
• Reflects the fact that the UNIX kernel always executes
in the context of some process.
Process Control
• Process creation in UNIX is made by means of the kernel system call,
fork().
• When a process issues a fork request, the OS performs the following
functions:
– It allocates a slot in the process table for the new process.
– It assigns a unique process ID to the child process.
– It makes a copy of the process image of the parent, with the exception of
any shared memory.
– It increments counters for any files owns by the parent, to reflect that an
additional process now also owns those files.
– It assign the child process to the Ready to Run state.
– It returns the ID number of the child to the parent process, and a 0 value to
the child process.
Process Description
• All of this work is accomplished in kernel mode in
the parent process. When the kernel has completed
these functions, it can do one of following, as part
of the dispatcher routine:
– Stay in the parent process. Control returns to user mode
at the point of the fork call of the parent.
– Transfer control to the child process. The child process
begins executing at the same point in the code as parent,
namely at the return from the fork call.
– Transfer control to another process. Both parent and
child are left in the Ready to Run state.
Process Management System
Call – fork()
• Creates a new process (child)
• Parent and children execute concurrently
• Each process can fork another process thus creating a
process hierarchy
• A process can choose to wait for its child to terminate
fork()
• When fork() is executed, it makes two identical copies of the
address space
• Both processes start execution afterwards
• Therefore parent and child runs independently

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 {

public static void main (String [] args) throws IOException {

        String [] Command = null;

        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);

        BufferedReader Resultset = new BufferedReader(


                        new InputStreamReader (
                        Findspace.getInputStream()));

        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

• Abraham Silberschatz, Peter B. Galvin, Greg


Gagne (2010). Operating System Concepts
8th ed. With Java
ISBN: 978-0-470-50949-4
Thank You

You might also like