0% found this document useful (0 votes)
48 views

UNIT - 3 - Process Concepts

This document discusses key concepts related to process management in operating systems. It defines a process as an instance of a computer program being executed that includes code, data, and execution context. Processes transition between different states like new, running, ready, waiting, and terminated. The operating system manages processes using a process control block that stores process-specific data and context. It also covers how processes are created, terminated, organized in hierarchies, and how they can cooperate through shared data and communication.

Uploaded by

Ayush Shrestha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

UNIT - 3 - Process Concepts

This document discusses key concepts related to process management in operating systems. It defines a process as an instance of a computer program being executed that includes code, data, and execution context. Processes transition between different states like new, running, ready, waiting, and terminated. The operating system manages processes using a process control block that stores process-specific data and context. It also covers how processes are created, terminated, organized in hierarchies, and how they can cooperate through shared data and communication.

Uploaded by

Ayush Shrestha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Process Management: Process

Concept
• DEFINATION OF PROCESS
• THE PROCESS MODEL
• PROCES STATES
• PROCESS STATE TRANSITION
• THE PROCESS CONTROL BLOCK
• OPERATION ON PORCESS(CREATION, TERMINATION,
HIERARCHIES, IMPLEMENTATION)
• CO OPERATING PROCESS
• SYSTEM CALLS(PROCESS MANAGEMENT, FILE
MANAGEMENT, DIRECTORY MANAGEMENT)
Process concept
• Lets take one real life example: Ram is
preparing a fry momo for his family
- Ram- CPU
- Momo recipe – program
- Ingredients – input data
- Activities – process
- Reading recipe
- Fetching the ingredients
- Cooking momo.
Definition of Process
• In an operating system, a process is an instance of a computer program that is
being executed.
• It includes the program code, data and the execution context(such as the values of
registers and the program counter).
• A process generally also includes process stack, which contains temporary data
(function parameters, return address and local variables) and data section, which
contains global variables.
• A process may also include a heap which is memory that is dynamically allocated
during process run time.
• A whole program itself is not a process it is passive entity. 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.
• For example: the text editor program transition from being a passive entity (idle
and waiting for user input) to an active entity by processing user interactions,
interacting with the file system , and responding to various events can be call
process.
THE PROCESS MODEL
• In the process model all the runnable software on the computer is
organized into a number of sequential processes. Each process has
its own virtual CPU.
• But in real CPU switches back and forth from process to process.
This rapid switching is known as multiprogramming.
• Process Model 1: Multiprogramming: In this there is four program
in memory. We have single shared processor by all programs.
• There is only one program counter for all program in memory. In
this first program counter is initialized to execute the part of
program A then with the help of process switch it transfer control to
program B and execute some part of it. After that program counter
for program C is active and execute some part of it.. and so on till all
the task is not completed.
Process model
Process model 2: Multiprocessing:
- There is 4 processes each with own flow of control (i.e own
logical program counter )and each one running
independently.
- There is only one physical program counter so when each
process runs its logical counter is loaded into the real program
counter. When it finished the physical program is saved in the
process stored logical program counter in memory.
Process model 3: One program at one:
- At any given instant only one process run and other process
after some interval of time
- In the other point of view all processes progress but only one
process actually runs at given instant of time.
Process model
Process states
• As a process executes, it change state. The state of a
process is defined in part by the current activity of that
process. A process may be in one of the following states:
- New: The process is being created
- Running: Instructions are being executed
- Waiting: The process is waiting for some event to
occur(such as an I/O completion or reception of a signal)
- Ready: The process is waiting to be assigned to a processor
- Terminated: The process has finished execution
The states that they represent are found on all system, it is
important to realize that only one process can be running on
any processor at any instant of time. But many process may be
in ready and waiting state.
Process state transition
Process state diagram
The process control Block
- Each process is represented in the operating system by a process control
block also called task control block.
- The PCB simply serves as the repository for any information that may vary
from process to process.
- A process control block is a data structure maintained by the operating
system for every process and is identified by process id(PID).
- It lies in kernel memory space and maintained for a process throughout its
lifetime and is deleted once the process terminates.
- It contains many pieces of information associated with a specific process
including:
1. Process id: Unique id to each process
2. Process state: The state may be new, ready, running, waiting ,etc
3. Program counter: The counter indicates the address of the next instruction
to be executed for this process.
4. CPU registers: The registers vary in number and type, depending on the
computer architecture. They include accumulators, index registers, stack
pointers and general purpose registers, etc. They allow the process to be
continued correctly afterward
The process control block
4. CPU scheduling information: This information includes a process
priority, pointers to scheduling queues, and any other scheduling
parameters.
5. Memory management information: This information may include
such items as the value of the base and limit registers and the page
tables or the segment tables depending on the memory system used
by the operating system.
6. Accounting information: This information includes the amount of
cpu and real time used, time limits, account numbers, job or process
numbers, and so on
7. I/O status : This information includes the list of I/O devices allocated
to the process, a list of open files and so on.
• IDEA to REMEMBER: Id card is essential to enter in state and must
show in counter, Then CPU schedule it in memory keeping all
accounting and I/O information.
The process control block
Context Switching
• Context switch means stopping one process and
restarting another process
• When an event occur , os saves the state of an active
process and restore the state of new process
• Sequence of action:
1. OS takes control through interrupt
2. Saves context of running process PCD
3. Reload context of new process from the new process
PCB
4. Return control to new process
Operation on process
Creation:
- Execution of a process creation system call by a running process
fork() in linux and createProcess in windows
- User can request to create a new process by executing new
application.
- Major event that cause process to be created:
1. System initialization :At the time of system booting various
background and foreground process are created.
2. Execution of a process creation system call by running process: a
running process will issue system call like fork() or createProcess().
3. A user request to create a new process: User can start process by
clicking an icon or typing any command
4. Initiation of a batch job: In large mainframe or batch system
process can be created with batch job.
Operation on process
Termination: Following are the condition that cause the
process to terminate:
1. Normal exit: Terminated because process has done its
work
2. Error exit: The process discovers a fatal error e.g user
types wrong command or necessary file do not exist in
system ,etc.
3. Fatal error: An error caused by a process ofteh due to a
program bug. Eg. Executing an illegal instruction, divided
by zero, etc.
4. Killed by another process: A process executes a system call
telling the OS to kill some other process using kill system
call.
Normal exit, fatal error and error exit
examples.
Operation on process
Process hierarchies
- Parent process can create child process, an child process can
create its own child process.
- Unix has hierarchy concept which is known as process group
and windows has no concept of this.
Operation on process
• Implementation of process:
- For process, allocation for particular process a piece of an OS kernel
is called scheduler .
- The lowest layer of a process- structured operating system handles
interrupts and scheduling. Above that layer there are sequential
processes.
- To implement the process model, the operating system maintains a
table called process table with one entry per process. The entries
can be referred as PCB.
- These entry contains important information about each process like
pid, program counter, stack pointer, memory allocation, etc that
process need to save.
- The process is switched from running to ready or blocked state so
that it can be restarted later as if it had never been stopped.
Operation on process
• What lowest level of OS does when an interrupt occurs:
1. Hardware stack program counter, etc
2. Hardware loads new program counter from interrupt
vector
3. Assembly language procedure saves registers
4. Assembly language procedure set up new stack
5. interrupt service runs(Typically reads and buffers input)
6. Scheduler decides which process is to run next.
7. C procedure returns to the assembly code.
8. Assembly language procedure starts up new current
process.
Co –operating processes
• The concurrent processes executing in the OS may be
either independent or co-operating.
• Independent process cannot affect or be affected by
the execution of another process but co –operating
process can.
• So we can say any process that shares data with other
processes is co-operating process.
• Co operating processes are fundamental in the
development of multi- threaded and multi- processing
applications, where multiple tasks or threads need to
work together to accomplish a larger goal.
Co –operating process
There are different mechanisms for processes to co-
operate:
Shared memory: Process can communicate by sharing a
portion of memory allowing them to exchange
information
Message Passing: Processes can communicate by sending
and receiving messages. This can be done through various
inter process communication IPC mechanisms.
Synchronization: Processes often need to synchronized
their execution to avoid conflicts and ensure correct
operation.
Inter process Communication
- Communication between processes in the control of the OS is called inter process
communication or simply IPC
- Co operating process require an inter process communication mechanism that will
allow them to exchange data and information
- There are two fundamental models of IPC:
a. Message passing
b. Shared memory
System call
• The interface between OS and user program is
defined by the set of system calls that OS
provides.
System call
- A system call is the programmatic way in which a
computer program requests a service from the kernel
of the operating system it is executed on.
- A computer program makes a system call when it
makes a request to the operating system kernel.
- System call provides the services of the operating
system to the user program via Application program
interface(API)
- System calls are the only entry points into the kernel
system
- All program needing resources must use system calls.
System call
1. ps(process status): is used to provide
information about the currently running
processes
2. fork: Used for creating a new process
3. wait: wait system call blocks the calling process
until one of its child process exits. After child
process terminates parent continues its
execution after wait system call instruction
4. exit : terminates the running process normally.
5. exec family: the exec family of functions replaces
the current running process with a new process.
System call category
System call
Process Management: This system calls
performs the task of process creation, process
termination, etc
Windows Unix Description

CreateProcess() fork() To create new process

ExitProcess() exit() Terminate program


execution
WaitForSingleObject() wait() To wait for execution
System call
File Management: This system calls performs the
task of opening, closing ,reading from or writing
to file .
Windows Unix Description

CreateFile() open() To open file

ReadFile() read() To read file content

WriteFile() write() To write the content on file

CloseHandle() Close() To close open file


System call
Device Management: Device management does
the job of device manipulation like reading from
device buffers, writing into device buffers, etc. .
Windows Unix Description

SetConsoleMode() ioctl() Referred to as input and


output control
ReadConsole() read() To read console

WriteConsole() write() To write console


Assignment
• Explain different Process state with appropriate
diagram.
• How can you say that process control block is a
data structure. Explain with valid reasons.
• What are the fundamentals of co- operating
process . Explore and present with appropriate
diagrams.
• Research how system call works and understand
the basis of basic windows and linux system calls.

You might also like