SlideShare une entreprise Scribd logo
1  sur  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.

Contenu connexe

Tendances

Process management in os
Process management in osProcess management in os
Process management in os
Miong Lazaro
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process Synchronization
Wayne Jones Jnr
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidance
wahab13
 

Tendances (20)

Process state in OS
Process state in OSProcess state in OS
Process state in OS
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process Concepts
 
Operating systems system structures
Operating systems   system structuresOperating systems   system structures
Operating systems system structures
 
Operating System-Process Scheduling
Operating System-Process SchedulingOperating System-Process Scheduling
Operating System-Process Scheduling
 
Context switching
Context switchingContext switching
Context switching
 
OS Memory Management
OS Memory ManagementOS Memory Management
OS Memory Management
 
Lecture 5 process concept
Lecture 5   process conceptLecture 5   process concept
Lecture 5 process concept
 
Process of operating system
Process of operating systemProcess of operating system
Process of operating system
 
Process scheduling algorithms
Process scheduling algorithmsProcess scheduling algorithms
Process scheduling algorithms
 
CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
 
5 Process Scheduling
5 Process Scheduling5 Process Scheduling
5 Process Scheduling
 
Scheduling
SchedulingScheduling
Scheduling
 
Os unit 3 , process management
Os unit 3 , process managementOs unit 3 , process management
Os unit 3 , process management
 
Swapping | Computer Science
Swapping | Computer ScienceSwapping | Computer Science
Swapping | Computer Science
 
Operating System Lecture Notes
Operating System Lecture NotesOperating System Lecture Notes
Operating System Lecture Notes
 
Operating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and DeadlocksOperating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and Deadlocks
 
Process management in os
Process management in osProcess management in os
Process management in os
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process Synchronization
 
Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidance
 

Similaire à 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
 
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
 

Similaire à 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
 
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...
 
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
 
Lecture5
Lecture5Lecture5
Lecture5
 
Operating Systems PPT 1 (1).pdf
Operating Systems PPT 1 (1).pdfOperating Systems PPT 1 (1).pdf
Operating Systems PPT 1 (1).pdf
 

Dernier

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+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
 

Dernier (20)

Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
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
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%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 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...
 

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.