0% found this document useful (0 votes)
23 views21 pages

Process 0 MH

The document discusses key concepts related to operating system processes including: 1) A process is a program in execution that is represented in the OS by a process control block containing the process's state, resources, and scheduling information. 2) Processes can be in various states like running, waiting, ready, and terminated. Context switching occurs when the CPU switches between processes. 3) Operations on processes include process creation where a parent process spawns a child, and process termination which can be through exit, kill, or error. 4) Processes block when waiting for events like I/O and message passing, and the OS schedules processes among ready, wait, and job queues.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views21 pages

Process 0 MH

The document discusses key concepts related to operating system processes including: 1) A process is a program in execution that is represented in the OS by a process control block containing the process's state, resources, and scheduling information. 2) Processes can be in various states like running, waiting, ready, and terminated. Context switching occurs when the CPU switches between processes. 3) Operations on processes include process creation where a parent process spawns a child, and process termination which can be through exit, kill, or error. 4) Processes block when waiting for events like I/O and message passing, and the OS schedules processes among ready, wait, and job queues.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Operating system

Process
Lecture topics
 Process introduction.
 Process state.
 Process control Block.
 Context Switch.
 Operations on processes.
 Scheduling Queues.
Process introduction
 A process is a program in execution. For example,
when we write a program in C or C++ and compile it,
the compiler creates binary code. The original code
and binary code are both programs. When we actually
run the binary code, it becomes a process.
 A process is an ‘active’ entity instead of a program,
which is considered a ‘passive’ entity.
Process introduction
 Sometimes we use the terms job and process almost
interchangeably.
 Process – A program in execution;process execution
must progress in sequential fashion.A process
includes:
program counter.
Stack.
Data section.
Process state
 As a process executes, it changes state.
 The state of a process is defined in part by the current
activity of that process.
 Each process may be in one of the following states:
1. New: The process is being created.
2. Running: instructions are being executed.
3. Waiting: the process is waiting for some event to occur(such
as I/O completion or reception of a signal.)
4. Terminated: the process has finished execution.
Diagram of Process State
Process Control Block
 Each process is represented in the operating system by
process control block(PCB)- also called a task control
block.
PCB includes:
 Process state.
The state may be new , ready, running ,waiting, halted, and so on
 Program counter indicates the address of the next instruction to
be executed for this process.
 CPU registers.
 The registers vary in number and type, depending on the
computer architecture.
Process Control Block
 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.
 CPU- scheduling information
 This information includes a process priority, pointers to sched -
uling queues, and any other scheduling parameters.
 Memory –management information.
this information may include such information as the value of the
base ,or the segment tables, depending on the memory system used
by operating system.
Process Control Block
 Accounting information
This information includes the amount of CPU and real time used,
time limits, account members, job or process numbers and so on.
 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.
In brief, the PCB simply serves as the repository for any
information that may vary from process to process.
Process Number(or Process ID)

Current process state

CPU scheduling information


Program counter

Other CPU registers

Memory management information

Other information(e,g list of open


files,name of executable,identity of
owner,CPU time used so farm devices owned)

Memory management information

Diagram of Process Control Block


Context switch
 CPU switching from one process to another process is called a
context switch.
 Execution state of running process has to be saved and
execution state of next process has to be loaded(context is
switched)
 Time to save old and load new processes execution state is
called context-switch time.
 This time is overhead the system does no useful work while
switching. It needs to be small.
 To depends on hardware support.
Context Switch illustrated
Operations on Processes
 The systems must provide a mechanism
for process creation and termination.
Process Creation
 Nearly all systems are hierarchical : parent processes
create children 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 terminates.
• Address space
 Child is duplicate of parent.
 Child has a program loaded into it.
Process Creation
E.G on Unix: fork() system call create anew process
 All resources shared (i.e child is a clone)
 Execve()system call used to replace process ‘ memory with
new program
 createProcess() syscall includes name of program to executed.
Process Terminartion
 Process executes last statement and asks the
operating system to delete it (exit)
 Output data from child to parent(wait).
 Process ‘ resources are de-allocated by the OS.
 Process performs an illegal operation, e.g
 Makes an attempt to a cess memory to which it is not
authorized
 Attempts to execute a privileged instruction.
Process Termination
 Parent may terminate execution of child
process(abort,kill) e.g because
 Child has executed allocated resources.
 Task assigned to child is no longer required.
 Parent is exiting(“cascading termination”)
 Many operating systems do not allow a child to continue if
parent terminates.
 E.g Unix has ExitProcess() for self-termination and
TerminateProcess() for killing other processes.
 In general, a process blocks on an a process blocks
on an event , e.g.
 An I/O device completes an operation.
 Another process sends a message.
 Assume OS provides some kind of general-purpose
blocking primitive
e.g await()
 Concurrency issues need to be handled carefully.
Process Blocking
If(no key being pressed)
Await(keypress);
Print(“key has been pressed !:\n”);
}
//handle keyboard input
Scheduling Queues
Scheduling queues refers to queues of processes or
devices. The queue consists of all processes in the
system.
Scheduling Queues
Scheduling Queues
• Job queue.
• Batch processes awaiting admission.
• Ready Queue.
• Set of all processes residing in main memory , ready to
execute.
• Wait Queue(s).
• Set of processes waiting for an I/O device(or for other
processes).

You might also like