PPT-Unit-3-Process Management
PPT-Unit-3-Process Management
Chapter Outcomes:
• Explain the functions carried out in the given process state.
• Describe the function of the given component of process stack in PCB.
• Explain characteristics of the given multithreading model.
• Describe method of executing the given process command with example
Learning Objectives:
• To understand Concepts of Process, its States and PCB
• To learn Process Management and Scheduling
• To study Queues and Schedulers with their Types
• To learn Concept of InterProcess Communication (IPC)
• To study Basic Concepts of Threads and Multithreading
• To understand various Process Execution Commands like ps, wait, kill etc.
Process
• A process is defined as, "an entity which represents the basic unit of work to be
implemented in the system".
• A process is defined as, "a program under execution, which competes for the CPU time and
other resources.“
• A process is a program in execution. Process is also called as job, task and unit of work.
• The execution of a process must progress in a sequential fashion. That is, at any time, at
most one instruction is executed on behalf of the process.
• A process is an instance of an executing program, including the current values of the
program counter, registers and variables.
• Logically each process has its separate virtual CPU. In actual, the real CPU switches from
one process to another.
• A process is an activity and it has a program, input, output and a state.
Process in Memory
• A process is defined as, "a program under execution, which
competes for the CPU time and other resources."
Each process has following sections:
• A Text section that contains the program code.
• A Data section that contains global and static variables.
• The heap is used for dynamic memory allocation, and is managed
via calls to new, delete, malloc, free, etc.
• The stack is used for local variables. A process stack which
contains the temporary data (such as subroutine parameters,
return addresses, and temporary variables). Space on the stack is
reserved for local variables when they are declared (at function
entrance or elsewhere, depending on the language), and the
space is freed up when the variables go out of scope.
• A program counter that contains the contents of processor’s
registers.
Difference between Program and Process
Program Process
A program is a series of instructions to perform Process is a program in execution.
a particular task.
Program is given as a set of process. In some Process is a part of a program. Process is the
cases we may divide a problem into number of part where logic of that particular program
parts. At these times we write a separate logic exists
for each part known as process
It is stored in secondary storage. Process is stored in memory.
Ready State: When the process is ready to execute but it is waiting for the cpu to execute then
this is called as the ready state. After the completion of the input and outputs the process will
be on ready state means the process will wait for the processor to execute.
Running State: The process that is currently being executed. When the process is running
under the cpu, or when the program is executed by the cpu, then this is called as the running
state process and when a process is running then this will also provide us some outputs on the
screen.
Process State
Waiting or Blocked: A process that cannot execute until some event occurs or an I/O
completion. When a process is waiting for some input and output operations then this is called
as the waiting state. And in this state process is not under the execution instead the process is
stored out of memory and when the user will provide the input then this will again be on
ready state.
Terminated State: After the completion of the process, the process will be automatically
terminated by the CPU, so this is also called as the terminated state of the process. After
executing the whole process the processor will also de-allocate the memory which is allocated
to the process. So this is called as the terminated process.
Process State
Types of Tables maintain by Operating Systems
Memory Tables are used to keep track of both main and secondary memory. Some of main
memory is reserved for use by the operating system; the remainder is available for use by
processes.
I/O Tables are used by the operating systems to manage the I/O devices and channels of the
computer system. At any given time, an I/O device may be available or assigned to a particular
process.
File Tables provide information about the existence of files, their location on secondary
memory, their current status another attributes.
Process Tables are used to manage processes a process must include a program or set of
programs to be executed.
Process Control Block (PCB)
• Each process is represented in the
operating system by a Process Control Block
(PCB) also called as Task Control Block
(TCB).
• When a process is created, operating
system creates a corresponding PCB and
released whenever the process terminates.
• A PCB stores descriptive information
pertaining to a process, such as its state,
program counter, memory management
information, information about its
scheduling, allocated resources, accounting
information, etc. that is required to control
and manage a particular process.
Process Control Block (PCB)
1. Process Number: Each process is identified by its process number, called Process
Identification Number (PID). Every process has a unique process-id through which it is
identified. The process-id is provided by the OS. The process id of two processes could not be
same because process-id is always unique.
2. Priority: Each process is assigned a certain level of priority that corresponds to the relative
importance of the event that it services process priority is the preference of the one process
over other process for execution. Priority may be given by the user/system manager or it may
be given internally by OS. This field stores the priority of a particular process.
3. Process State: This information is about the current state of the process. The state may be
new, ready, running, and waiting, halted, and so on.
4. Program Counter: The counter indicates the address of the next instruction to be executed
for this process.
Process Control Block (PCB)
5. 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, plus any condition-code information. Along with the program counter, this state
information must be saved when an interrupt occurs, to allow the process to be continued
correctly afterward.
7. Memory Management Information: This information may include such information as the
value of the base and limit registers, the page tables, or the segment tables, depending on the
memory system used by the operating system.
8. Accounting Information: This information includes the amount of CPU and real time used,
time limits, account numbers, job or process numbers, and so on.
Process Control Block (PCB)
9. I/O Status Information: This information includes the list of I/O devices allocated to the
process, a list of open files, and so on.
10. File Management: It includes information about all open files, access rights etc.
11. Pointer: Pointer points to another process control block. Pointer is used for maintaining
the scheduling list.
Process Creation
When a new process is to be added to those currently being managed, the operating system
builds the data structures that are used to manage the process and allocates address space in
main memory to the process. This is the creation of a new process.
Parent process create children processes, which, in turn create other processes, forming a tree
of processes
Resource sharing
• Parent and children share all resources
• Children share subset of parent’s resources
• Parent and child share no resources
Execution
• Parent and children execute concurrently
• Parent waits until children terminate
Process Creation
UNIX examples
• fork system call creates new process
• exec system call used after a fork to
replace the process’ memory space
with a new program
System call CreateProcess() in Windows
and fork() in Unix which tells the
operating system to create a new
process.
Process Termination
Depending upon the condition, a process may be terminated either normally or forcibly by
some another process.
Normal termination occurs when the process completes its task (operation) and invokes an
appropriate system call ExitProcess( ) in Windows and exit( ) in Unix to tell the operating
system that it is finished.
A process may cause abnormal termination of some another process. For this, the process
invokes an appropriate system call TerminateProcess( ) in Windows and kill( ) in Unix that tells
the operating system to kill some other process.
Process Scheduling
• As we know that we can perform many programs at a time on the computer, but there is a
single CPU. So for running all the programs concurrently or simultaneously, then we use the
scheduling.
• Processes are the small programs those are executed by the user according to their
request. CPU executes all the process according to some rules or some schedule.
• Scheduling is that in which each process have some amount of time of CPU. Scheduling
provides time of CPU to the each process.
• When two or more processes compete for the CPU at the same time then choice has to be
made which process to allocate the CPU next. This procedure of determining the next
process to be executed on the CPU is called process scheduling and the module of
operating system that makes this decision is called the scheduler.
• Processor scheduling is one of the primary function of a multiprogramming operating
system.
Process Scheduling
Scheduling Queue
• For a uniprocessor system, there will never be
more than one running process. If there are more
than one processes, the rest will have to wait until
the CPU is free and can be rescheduled.
• The processes, which are ready and waiting to
execute, are kept on a list called the ready queue.
• The list is generally a linked list. A ready queue
header will contain pointers to the first and last
PCB’s in the list. Each PCB has a pointer field
which points to the next process in the ready
queue.
• The list of processes waiting for a particular I/O
device is called a device queue. Each device has
its own device queue.
Scheduling Queue
• A process enters the system from
the outside world and is put in the
ready queue. It waits in the ready
queue until it is selected for the CPU.
After running on the CPU, its waits
for an I/O operation by moving to an
I/O queue.
• Eventually it is served by the I/O
device and returns to the ready
queue. A process continues this CPU,
I/O cycle until it finishes and then it
exits from the system.
Schedulers
• Schedulers are special system software’s
which handles process scheduling in
various ways. Their main task is to select
the jobs to be submitted into the system
and to decide which process to run.
• In other words, the job of process
scheduling is done by a software routine
(module) called as scheduler.
• Short Term Scheduler-(Context switching time): Short term scheduler will decide which
process to be executed next and then it will call dispatcher. A dispatcher is a software
that moves process from ready to run and vice versa. In other words, it is context
switching.
• In a user-level thread approach the cost of a context switch between threads less since the
operating system itself does not need to be involved–no extra system calls are required.
• A user-level thread is represented by a program counter; registers, stack, and small thread
control block (TCB).
• Creating a new thread, switching between threads, and synchronizing threads are done via
function calls into the library. This provides an interface for creating and stopping threads,
as well as control over how they are scheduled.
Kernel Thread
• In systems that use kernel-level threads, the operating system itself is aware of each
individual thread.
• Kernel threads are supported and managed directly by the operating system.
• A context switches between kernel threads belonging to the same process requires only
the registers, program counter, and stack to be changed; the overall memory management
information does not need to be switched since both of the threads share the same
address space. Thus context switching between two kernel threads is slightly faster than
switching between two processes.
• Kernel threads can be expensive because system calls are required to switch between
threads. Also, since the operating system is responsible for scheduling the threads, the
application does not have any control over how its threads are managed.
Thread Design Space
Difference between User Thread and Kernel Thread
User Level Thread Kernel Level Thread
User thread are implemented by users Kernel threads are implemented by
Operating System.
Operating system doesn’t recognized use Kernel threads are recognized by Operating
level threads system
User level threads are faster to create and Kernel level threads are slower to create
manage. and manage.
Implementation of user threads are easy. Implementation of kernel thread is
complicated.
Context switch time is less Context switch time is more
Difference between User Thread and Kernel Thread
User Level Thread Kernel Level Thread
If one user level thread perform blocking If one kernel thread perform blocking
operation then entire process will be operation then another thread can
blocked continue execution
User level thread can run on any operating Kernel level threads are specific to the
system operating system.
Example: Java thread, POSIX threads Example: Window Solaris
Multithreading Models
• One-to-One
• Many-to-One
• Many-to-Many
One-to-One Model
• The one-to-one model maps each user thread to a kernel thread.
• It provides more concurrency than the many-to-one model by allowing another thread to
run when a thread makes a blocking system call; it also allows multiple threads to run in
parallel on multiprocessors.
• Windows NT, Windows 2000 and OS/2 implement the one-to-one model.
One-to-One Model
Advantages of One-to-one Model:
• More concurrency because of multiple threads can run in parallel on multiple CPUs.
• Multiple threads can run parallel
• Less complication in the processing.
Example:
$ ps –f
UID PID PPID C STIME TTY TIME CMD
logon 1610 1603 0 14:09 pts/0 00:00:00 bash
logon 1715 1610 0 14:21 pts/0 00:00:00 ps -f
Ps command
$ ps –l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 1000 1610 1603 8 80 0 - 1858 wait pts/0 00:00:00 bash
0 R 1000 1665 1610 0 80 0 - 1193 - pts/0 00:00:00 ps
Attributes of –l options:
F: System flags assigned to the process by the kernel.
S: The state of the process (O = running on processor; S = sleeping; I=idle process; X: process
waiting for memory; R = runnable, waiting to run; Z = zombie, process terminated but parent
not available; T = process stopped).
UID: The user responsible for launching the process.
PID: The process ID of the process.
PPID: The PID of the parent process (if a process is started by another process).
Ps command
Attributes of –l options:
C: Processor utilization over the lifetime of the process.
PRI: PRI shows the priority with which the process is running. (higher numbers mean lower
priority).
NI: The nice value, which is used for determining priorities.
ADDR: ADDR shows the memory or disk address of the process.
SZ: The size of process is memory is indicated by the SZ column.
WCHAN: When process is executed, it may have to wait for system resources which are not yet
available. This indication is shown under WCHAN for running processes this column is blank.
TTY: The terminal device from which the process was launched.
TIME: The cumulative CPU time required to run the process.
CMD: The name of the program that was started.
Wait Command
• wait is a built-in shell command which waits for a given process to complete, and returns
its exit status. wait waits for the process identified by process ID pid (or the job specified by
job ID jobid), and reports its termination status.
• If an ID is not given, wait waits for all currently active child processes, and the return status
is zero. If the ID is a job specification, wait waits for all processes in the job's pipeline.
Syntax: wait pid
Example: wait 2112
• Wait for process 2112 to terminate, and return its exit status.
Sleep Command
• The sleep command is used to delay for a specified amount of time.
• The sleep command pauses for an amount of time defined by NUMBER. SUFFIX may be "s"
for seconds (the default), "m" for minutes, "h" for hours, or "d" for days.
Syntax: sleep NUMBER[suffix]
Example: Sleep 10
Delay for 10 seconds.
Exit command
• The exit command terminates a script, just as in a C program.
• It can also return a value, which is available to the script's parent process. Issuing the exit
command at the shell prompt will cause the shell to exit.
Syntax: exit
Thank You
Vijay Patil
Department of Computer Engineering (NBA Accredited)
Vidyalankar Polytechnic
Vidyalankar College Marg, Wadala(E), Mumbai 400 037
E-mail: vijay.patil@vpt.edu.in 62
63