SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Process
Objectives
• At the end of this topic, students should be able to:
• Define a Process
• Describe a Process State
• Describe the Process Operations
• Explain a Process Control Block (PCB)
Process
• a process is an instance of a computer program that is being executed.
• It contains the program code and its current activity.
• The execution of a process must progress in a sequential fashion.
• A process is defined as an entity which represents the basic unit of work to
be implemented in the system.
• To put it in simple terms, we write our computer programs in a text file and
when we execute this program, it becomes a process which performs all
the tasks mentioned in the program.
• When a program is loaded into the memory and it becomes a process, it
can be divided into four sections ─ stack, heap, text and data.
Process inside main memory
Program
• A program is a piece of code which may be a single line or
millions of lines.
• A computer program is usually written by a computer
programmer in a programming language.
• For example, here is a simple program written in C
programming language:
Processes vs. Programs
• A process is different than a program
• Program: Static code and static data
• Process: Dynamic instance of code and data
• No one-to-one mapping between programs and processes
• Can have multiple processes of the same program: Example:
many users can run “ls” at the same time
• One program can invoke multiple processes: Example: “make”
runs many processes to accomplish its work
Process Life Cycle/ Process State
• When a process executes, it passes through different states.
• These stages may differ in different operating systems, and the names
of these states are also not standardized.
• In general, a process can have one of the following five states at a
time.
Processes can be any of the following states :
• Start/New - The process is at the initial stage of being created.
• Ready - The process is waiting to be assigned to a processor. Ready processes
are waiting to have the processor allocated to them by the operating system so
that they can run. Process may come into this state after Start state or while
running it by but interrupted by the scheduler to assign CPU to some other
process.
• Running - The CPU is working on this process's instructions. Once the process
has been assigned to a processor by the OS scheduler, the process state is set
to running and the processor executes its instructions.
• Waiting - Process moves into the waiting state if it needs to wait for a resource,
such as waiting for user input, or waiting for a file to become available.
• Termination/ Exit - Once the process finishes its execution or it is terminated
by the operating system, it is moved to the terminated state where it waits to
be removed from main memory. The process has completed.
Diagram of process state
Process State Transitions
• Following are six(6) possible transitions among above mentioned five (5)
states
• Transition 1 occurs when process discovers that it cannot continue. If
running process initiates an I/O operation before its allotted time expires,
the running process voluntarily relinquishes the CPU. This state transition is:
Block (process-name): Running → Blocked
• Transition 2 occurs when the scheduler decides that the running process has
run long enough and it is time to let another process have CPU time. This
state transition is:
Time-Run-Out (process-name): Running → Ready.
• Transition 3 occurs when all other processes have had their share and
it is time for the first process to run again This state transition is:
Dispatch (process-name): Ready → Running.
• Transition 4 occurs when the external event for which a process was
waiting (such as arrival of input) happens. This state transition is:
Wakeup (process-name): Blocked → Ready.
• Transition 5 occurs when the process is created. This state transition
is:
Admitted (process-name): New → Ready.
• Transition 6 occurs when the process has finished execution. This
state transition is:
Exit (process-name): Running → Terminated.
Process State Transition Diagram
• An active process is normally in one of the five states in the diagram. The arrows
show how the process changes states.
• A process is running if the process is assigned to a CPU. A process is removed
from the running state by the scheduler if a process with a higher priority
becomes runnable. A process is also pre-empted if a process of equal priority is
runnable when the original process consumes its entire time slice.
• A process is runnable in memory if the process is in primary memory and ready
to run, but is not assigned to a CPU.
• A process is sleeping in memory if the process is in primary memory but is
waiting for a specific event before continuing execution. For example, a process
sleeps while waiting for an I/O operation to complete, for a locked resource to be
unlocked, or for a timer to expire. When the event occurs, a wakeup call is sent to
the process. If the reason for its sleep is gone, the process becomes runnable.
• When a process' address space has been written to secondary memory, and that
process is not waiting for a specific event, the process is runnable and swapped.
• If a process is waiting for a specific event and has had its whole address
space written to secondary memory, the process is sleeping and swapped.
• If a machine does not have enough primary memory to hold all its active
processes, that machine must page or swap some address space to
secondary memory.
• When the system is short of primary memory, the system writes individual
pages of some processes to secondary memory but leaves those processes
runnable. When a running process, accesses those pages, the process
sleeps while the pages are read back into primary memory.
• When the system encounters a more serious shortage of primary memory,
the system writes all the pages of some processes to secondary memory.
The system marks the pages that have been written to secondary memory
as swapped. Such processes can only be scheduled when the system
scheduler daemon selects these processes to be read back into memory.
Process Operations
Process Creation
• In general-purpose systems, some way is needed to create processes
as needed during operation.
• There are four principal events led to processes creation.
System initialization.
Execution of a process Creation System calls by a running process.
A user request to create a new process.
Initialization of a batch job.
• Background processes that stay in background sleeping but suddenly springing to life to
handle activity such as email, webpage, printing, and so on.
• Background processes are called daemons. This call creates an exact clone of the calling
process.
• A process may create a new process by some create process such as 'fork'.
• Creating process is called parent process and the created one is called the child
processes.
• Only one parent is needed to create a child process.
• Note that unlike plants and animals that use sexual representation, a process has only
one parent.
• This creation of process (processes) yields a hierarchical structure of processes.
• Notice that each child has only one parent but each parent may have many children.
• After the fork, the two processes, the parent and the child, have the same memory
image, the same environment strings and the same open files.
• After a process is created, both the parent and child have their own distinct address
space.
• If either process changes a word in its address space, the change is not visible to the
other process.
• Following are some reasons for creation of a process
User logs on.
User starts a program.
Operating systems creates process to provide service,
e.g., to manage printer.
Some program starts another process, e.g., Netscape
calls xv to display a picture.
Process Termination
• A process terminates when it finishes executing its last statement.
• Its resources are returned to the system, it is purged from any system lists or tables,
and its process control block (PCB) is erased i.e., the PCB's memory space is returned
to a free memory pool.
• The new process terminates the existing process, usually due to following reasons:
Normal Exist Most processes terminates because they have done their job. This call is
exist in UNIX.
Error Exist When process discovers a fatal error. For example, a user tries to compile a
program that does not exist.
Fatal Error An error caused by process due to a bug in program for example, executing
an illegal instruction, referring non-existing memory or dividing by zero.
Killed by another Process A process executes a system call telling the Operating
Systems to terminate some other process. In UNIX, this call is kill. In some systems
when a process kills all processes it created are killed as well (UNIX does not work this
way).
Process Control Block
• A Process Control Block (PCB) is a data structure maintained by the
Operating System for every process.
• The PCB is identified by an integer process ID (PID).
• A PCB keeps all the information needed to keep track of a process as
listed below in the table:
Simplified PCB Diagram
PCB ctd’
• The architecture of a PCB is completely dependent on Operating
System and may contain different information in different operating
systems.
• The PCB is maintained for a process throughout its lifetime, and is
deleted once the process terminates.
Context Switching
• Process Context = machine environment
during the time the process is actively
using the CPU.
• i.e. context includes program counter,
general purpose registers, processor status
register (with C,N,V and Z flags), . . .
• To switch between processes, the OS
must:
a) save the context of the currently
executing process (if any), and
b) restore the context of that being
resumed.
• Time taken depends on h/w support.
Idle system
• What do we do if there is no ready process?
 halt processor (until interrupt arrives)
 saves power (and heat!)
 increases processor lifetime
 might take too long to stop and start.
• busy wait in scheduler
 quick response time
 ugly, useless
• invent idle process, always available to run
 gives uniform structure
 could use it to run checks
 uses some memory
 can slow interrupt response
• In general there is a trade-off between responsiveness and usefulness.

Weitere ähnliche Inhalte

Was ist angesagt?

Memory management
Memory managementMemory management
Memory management
Rajni Sirohi
 
5. spooling and buffering
5. spooling and buffering 5. spooling and buffering
5. spooling and buffering
myrajendra
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidance
wahab13
 

Was ist angesagt? (20)

Pthread
PthreadPthread
Pthread
 
SCHEDULING ALGORITHMS
SCHEDULING ALGORITHMSSCHEDULING ALGORITHMS
SCHEDULING ALGORITHMS
 
Distributed Operating System_1
Distributed Operating System_1Distributed Operating System_1
Distributed Operating System_1
 
Pipelining slides
Pipelining slides Pipelining slides
Pipelining slides
 
Memory management
Memory managementMemory management
Memory management
 
Multiprocessor architecture
Multiprocessor architectureMultiprocessor architecture
Multiprocessor architecture
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's types
 
Memory management
Memory managementMemory management
Memory management
 
Process state in OS
Process state in OSProcess state in OS
Process state in OS
 
5. spooling and buffering
5. spooling and buffering 5. spooling and buffering
5. spooling and buffering
 
Memory management
Memory managementMemory management
Memory management
 
Computer arithmetic
Computer arithmeticComputer arithmetic
Computer arithmetic
 
Os unit 3 , process management
Os unit 3 , process managementOs unit 3 , process management
Os unit 3 , process management
 
Process creation and termination In Operating System
Process creation and termination In Operating SystemProcess creation and termination In Operating System
Process creation and termination In Operating System
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Threads in Operating System | Multithreading | Interprocess Communication
Threads in Operating System | Multithreading | Interprocess CommunicationThreads in Operating System | Multithreading | Interprocess Communication
Threads in Operating System | Multithreading | Interprocess Communication
 
Threads .ppt
Threads .pptThreads .ppt
Threads .ppt
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidance
 
Pipeline processing - Computer Architecture
Pipeline processing - Computer Architecture Pipeline processing - Computer Architecture
Pipeline processing - Computer Architecture
 
Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory management
 

Ähnlich wie Lecture 2 process

Operating Systems chap 2_updated2 (1).pptx
Operating Systems chap 2_updated2 (1).pptxOperating Systems chap 2_updated2 (1).pptx
Operating Systems chap 2_updated2 (1).pptx
Amanuelmergia
 
Operating Systems chap 2_updated2.pptx
Operating Systems chap 2_updated2.pptxOperating Systems chap 2_updated2.pptx
Operating Systems chap 2_updated2.pptx
Amanuelmergia
 
Lecture 2- Processes.pdf
Lecture 2- Processes.pdfLecture 2- Processes.pdf
Lecture 2- Processes.pdf
Amanuelmergia
 
Chapter -2 operating system presentation
Chapter -2 operating system presentationChapter -2 operating system presentation
Chapter -2 operating system presentation
chnrketan
 
Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...
Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...
Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...
morganjohn3
 

Ähnlich wie Lecture 2 process (20)

Operating Systems chap 2_updated2 (1).pptx
Operating Systems chap 2_updated2 (1).pptxOperating Systems chap 2_updated2 (1).pptx
Operating Systems chap 2_updated2 (1).pptx
 
Operating Systems chap 2_updated2.pptx
Operating Systems chap 2_updated2.pptxOperating Systems chap 2_updated2.pptx
Operating Systems chap 2_updated2.pptx
 
Lecture 2- Processes.pdf
Lecture 2- Processes.pdfLecture 2- Processes.pdf
Lecture 2- Processes.pdf
 
UNIT I-Processes.pptx
UNIT I-Processes.pptxUNIT I-Processes.pptx
UNIT I-Processes.pptx
 
Chapter -2 operating system presentation
Chapter -2 operating system presentationChapter -2 operating system presentation
Chapter -2 operating system presentation
 
Unit 2_OS process management
Unit 2_OS process management Unit 2_OS process management
Unit 2_OS process management
 
Process management- This ppt contains all required information regarding oper...
Process management- This ppt contains all required information regarding oper...Process management- This ppt contains all required information regarding oper...
Process management- This ppt contains all required information regarding oper...
 
Operating System-Concepts of Process
Operating System-Concepts of ProcessOperating System-Concepts of Process
Operating System-Concepts of Process
 
OS-Process.pdf
OS-Process.pdfOS-Process.pdf
OS-Process.pdf
 
Processing management
Processing managementProcessing management
Processing management
 
PROCESS.pptx
PROCESS.pptxPROCESS.pptx
PROCESS.pptx
 
Process , Process states , Process Control Block in Operating Systems
Process , Process states , Process Control Block in Operating SystemsProcess , Process states , Process Control Block in Operating Systems
Process , Process states , Process Control Block in Operating Systems
 
Processes
ProcessesProcesses
Processes
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process Concepts
 
opearating system notes mumbai university.pptx
opearating system notes mumbai university.pptxopearating system notes mumbai university.pptx
opearating system notes mumbai university.pptx
 
Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...
Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...
Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...
 
Process of operating system
Process of operating systemProcess of operating system
Process of operating system
 
Engg-0505-IT-Operating-Systems-2nd-year.pdf
Engg-0505-IT-Operating-Systems-2nd-year.pdfEngg-0505-IT-Operating-Systems-2nd-year.pdf
Engg-0505-IT-Operating-Systems-2nd-year.pdf
 
Process Management
Process ManagementProcess Management
Process Management
 
Operating System.pptx
Operating System.pptxOperating System.pptx
Operating System.pptx
 

KĂźrzlich hochgeladen

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 

KĂźrzlich hochgeladen (20)

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 

Lecture 2 process

  • 2. Objectives • At the end of this topic, students should be able to: • Define a Process • Describe a Process State • Describe the Process Operations • Explain a Process Control Block (PCB)
  • 3. Process • a process is an instance of a computer program that is being executed. • It contains the program code and its current activity. • The execution of a process must progress in a sequential fashion. • A process is defined as an entity which represents the basic unit of work to be implemented in the system. • To put it in simple terms, we write our computer programs in a text file and when we execute this program, it becomes a process which performs all the tasks mentioned in the program. • When a program is loaded into the memory and it becomes a process, it can be divided into four sections ─ stack, heap, text and data.
  • 5.
  • 6. Program • A program is a piece of code which may be a single line or millions of lines. • A computer program is usually written by a computer programmer in a programming language. • For example, here is a simple program written in C programming language:
  • 7. Processes vs. Programs • A process is different than a program • Program: Static code and static data • Process: Dynamic instance of code and data • No one-to-one mapping between programs and processes • Can have multiple processes of the same program: Example: many users can run “ls” at the same time • One program can invoke multiple processes: Example: “make” runs many processes to accomplish its work
  • 8. Process Life Cycle/ Process State • When a process executes, it passes through different states. • These stages may differ in different operating systems, and the names of these states are also not standardized. • In general, a process can have one of the following five states at a time.
  • 9. Processes can be any of the following states : • Start/New - The process is at the initial stage of being created. • Ready - The process is waiting to be assigned to a processor. Ready processes are waiting to have the processor allocated to them by the operating system so that they can run. Process may come into this state after Start state or while running it by but interrupted by the scheduler to assign CPU to some other process. • Running - The CPU is working on this process's instructions. Once the process has been assigned to a processor by the OS scheduler, the process state is set to running and the processor executes its instructions. • Waiting - Process moves into the waiting state if it needs to wait for a resource, such as waiting for user input, or waiting for a file to become available. • Termination/ Exit - Once the process finishes its execution or it is terminated by the operating system, it is moved to the terminated state where it waits to be removed from main memory. The process has completed.
  • 11. Process State Transitions • Following are six(6) possible transitions among above mentioned five (5) states • Transition 1 occurs when process discovers that it cannot continue. If running process initiates an I/O operation before its allotted time expires, the running process voluntarily relinquishes the CPU. This state transition is: Block (process-name): Running → Blocked • Transition 2 occurs when the scheduler decides that the running process has run long enough and it is time to let another process have CPU time. This state transition is: Time-Run-Out (process-name): Running → Ready.
  • 12. • Transition 3 occurs when all other processes have had their share and it is time for the first process to run again This state transition is: Dispatch (process-name): Ready → Running. • Transition 4 occurs when the external event for which a process was waiting (such as arrival of input) happens. This state transition is: Wakeup (process-name): Blocked → Ready. • Transition 5 occurs when the process is created. This state transition is: Admitted (process-name): New → Ready. • Transition 6 occurs when the process has finished execution. This state transition is: Exit (process-name): Running → Terminated.
  • 14. • An active process is normally in one of the five states in the diagram. The arrows show how the process changes states. • A process is running if the process is assigned to a CPU. A process is removed from the running state by the scheduler if a process with a higher priority becomes runnable. A process is also pre-empted if a process of equal priority is runnable when the original process consumes its entire time slice. • A process is runnable in memory if the process is in primary memory and ready to run, but is not assigned to a CPU. • A process is sleeping in memory if the process is in primary memory but is waiting for a specific event before continuing execution. For example, a process sleeps while waiting for an I/O operation to complete, for a locked resource to be unlocked, or for a timer to expire. When the event occurs, a wakeup call is sent to the process. If the reason for its sleep is gone, the process becomes runnable. • When a process' address space has been written to secondary memory, and that process is not waiting for a specific event, the process is runnable and swapped.
  • 15. • If a process is waiting for a specific event and has had its whole address space written to secondary memory, the process is sleeping and swapped. • If a machine does not have enough primary memory to hold all its active processes, that machine must page or swap some address space to secondary memory. • When the system is short of primary memory, the system writes individual pages of some processes to secondary memory but leaves those processes runnable. When a running process, accesses those pages, the process sleeps while the pages are read back into primary memory. • When the system encounters a more serious shortage of primary memory, the system writes all the pages of some processes to secondary memory. The system marks the pages that have been written to secondary memory as swapped. Such processes can only be scheduled when the system scheduler daemon selects these processes to be read back into memory.
  • 16. Process Operations Process Creation • In general-purpose systems, some way is needed to create processes as needed during operation. • There are four principal events led to processes creation. System initialization. Execution of a process Creation System calls by a running process. A user request to create a new process. Initialization of a batch job.
  • 17. • Background processes that stay in background sleeping but suddenly springing to life to handle activity such as email, webpage, printing, and so on. • Background processes are called daemons. This call creates an exact clone of the calling process. • A process may create a new process by some create process such as 'fork'. • Creating process is called parent process and the created one is called the child processes. • Only one parent is needed to create a child process. • Note that unlike plants and animals that use sexual representation, a process has only one parent. • This creation of process (processes) yields a hierarchical structure of processes. • Notice that each child has only one parent but each parent may have many children. • After the fork, the two processes, the parent and the child, have the same memory image, the same environment strings and the same open files. • After a process is created, both the parent and child have their own distinct address space. • If either process changes a word in its address space, the change is not visible to the other process.
  • 18. • Following are some reasons for creation of a process User logs on. User starts a program. Operating systems creates process to provide service, e.g., to manage printer. Some program starts another process, e.g., Netscape calls xv to display a picture.
  • 19. Process Termination • A process terminates when it finishes executing its last statement. • Its resources are returned to the system, it is purged from any system lists or tables, and its process control block (PCB) is erased i.e., the PCB's memory space is returned to a free memory pool. • The new process terminates the existing process, usually due to following reasons: Normal Exist Most processes terminates because they have done their job. This call is exist in UNIX. Error Exist When process discovers a fatal error. For example, a user tries to compile a program that does not exist. Fatal Error An error caused by process due to a bug in program for example, executing an illegal instruction, referring non-existing memory or dividing by zero. Killed by another Process A process executes a system call telling the Operating Systems to terminate some other process. In UNIX, this call is kill. In some systems when a process kills all processes it created are killed as well (UNIX does not work this way).
  • 20. Process Control Block • A Process Control Block (PCB) is a data structure maintained by the Operating System for every process. • The PCB is identified by an integer process ID (PID). • A PCB keeps all the information needed to keep track of a process as listed below in the table:
  • 21.
  • 22.
  • 24. PCB ctd’ • The architecture of a PCB is completely dependent on Operating System and may contain different information in different operating systems. • The PCB is maintained for a process throughout its lifetime, and is deleted once the process terminates.
  • 25. Context Switching • Process Context = machine environment during the time the process is actively using the CPU. • i.e. context includes program counter, general purpose registers, processor status register (with C,N,V and Z flags), . . . • To switch between processes, the OS must: a) save the context of the currently executing process (if any), and b) restore the context of that being resumed. • Time taken depends on h/w support.
  • 26. Idle system • What do we do if there is no ready process?  halt processor (until interrupt arrives)  saves power (and heat!)  increases processor lifetime  might take too long to stop and start. • busy wait in scheduler  quick response time  ugly, useless • invent idle process, always available to run  gives uniform structure  could use it to run checks  uses some memory  can slow interrupt response • In general there is a trade-off between responsiveness and usefulness.