SlideShare a Scribd company logo
1 of 31
PROCESS MANAGEMENT
PREVIOUS VIDEO
• Introduction to operating system
• Kernel vs operating system
• Functions of operating system
• Examples of operating system and kernel
• System calls
• Interrupts
• Video Link + telegram link + form link in the description
AGENDA
• Program VS process
• Process control block
• Process states
• Process creation through fork()
• Exec(), wait() and exit() system calls
• Zombie and orphan process
INTERVIEW QUESTIONS
• Difference between a program and a process
• Which data structure is used to represent a process?
• List some important fields in Process Control Block
• What is INIT process in Linux?
• What are the different states of a process? Explain with process state
diagram.
• How will you create a new process in Linux?
• How does a parent process differ from a child process?
• Number of processes created with N fork() calls?
INTERVIEW QUESTIONS CONTINUED
• What is the use of exec(), wait() and exit() system calls?
• What happens if parent doesn’t wait for its child process?
• Give some real world examples where fork(), exec() and wait() system
calls are used?
• What is zombie process? What are the side effects of zombie
processes?
• What is an orphan process? How it differs from zombie process?
• Give examples of zombie and orphan process.
PROGRAM VS PROCESS
• Program – An executable file that is stored on the hard disk or a
secondary memory
• When you execute this file either by double clicking or from
command line, it becomes a process
• Program – Passive entity
• Process – Active entity
• Process memory = stack + data + heap + text
• Program is just the text section of memory
• Process is text section + a lot of other attributes
What are other attributes of a process?
• Program counter(PC) – Address of next instruction to be executed on
CPU
• Process states – new, ready, running, waiting etc.
• CPU registers – value of CPU registers are stored when context switch
happens
• List of open files that the process is using for reading and writing
• Process priority – Used in process scheduling
• Process ID – unique identifier for each process
• Parent process ID – Process ID of parent process
• Memory information – stack, heap, data, text
PROCESS CONTROL BLOCK
• These all attributes or information about a process are stored in a data structure
called Process Control Block(PCB).
• Struct task_struct {
pid_t pid;
long state;
int priority;
struct task_struct *parent;
struct files_struct *files;
struct mm_struct *mm;
long program_counter;
.
.
}
• Video: https://youtu.be/x2JIEgAVkTI
PROCESS STATES
• Batch operating system in old times
• Jobs were submitted in batches
• Jobs were first stored in job queue on disk
• Not all job can fit in main memory
• Selected jobs were loaded into main memory by long term scheduler
• These were kept in ready queue and scheduled by CPU scheduler or
short term scheduler
• Video: https://youtu.be/mhKr6Dnf2fA
PROCESS STATE DIAGRAM
WHAT EACH STATE MEANS?
• NEW
• BATCH OS – Job arrived in the job queue
• Time sharing OS – process is being created
• READY – Process waiting in ready queue for being assigned to a
CPU/processor
• RUNNING – Program is being executed on the CPU
• WAITING – Process is waiting for some event to occur (I/O)
• TERMINATED – Process has finished its execution.
WHEN DOES TRANSITION FROM RUNNING TO
READY HAPPENS?
• A hardware interrupt happens on the CPU
• A higher priority process arrives in the ready queue (preemptive
scheduling)
• Time slice of the process expires (Round robin scheduling)
• Program – helloworld.c
• Compile – gcc helloworld.c
• Executable – a.out
• Execute the program
• a.out is bought to RAM from disk
• A PCB is created (PC -> address of
first instruction )
• Enters ready queue
• CPU scheduler schedules it on CPU
• Running state
• CPU starts executing
• I/O – enters waiting state
• Time slice expires – ready state
• Terminated
INIT PROCESS
• First process that is started during booting of the system
• PID – 1
• This process keeps on running forever until you shut down.
• All other processes are either direct or indirect children of INIT
process.
• Pstree –p command to view the process tree on linux
PROCESS CREATION USING FORK
• CreateProcess() in Windows
• Fork() creates a new child process that is a copy of the parent process
• In what ways the child process differs from parent?
• PID
• Parent PID
• File locks
• Process utilization info
• In what ways they are similar?
• Program counter
• Memory ( unless fork() is followed by exec() )
• CPU registers
• priority
WHAT HAPPENS AFTER FORK() IS CALLED?
• Execution – Both process starts executing from the next line after
fork()
• Memory – stack, heap, text and data segment are duplicated for the
child process.
• Copy on write is used in modern implementation of fork.
• Copy the memory only when a write is being made to a memory
page.
• In most cases, fork() is followed by exec().
• Copy on write saves expensive recopying of memory
FORK CALL RETURN VALUES
• How do you differentiate between the the parent process and the
child process?
• Fork() returns PID of the child process to parent
• Fork() returns 0 to the child process
• Fork() returns -1 if there is any error
• Videos
• https://youtu.be/FXAvkNY1dGQ
• https://youtu.be/AyZeHBPKdMs
FORK CODE EXAMPLE
How may child processes?
fork();
fork();
Video: https://youtu.be/iZa2vm7A6mw
What if you want the child to run another
program?
• Shell program which helps in running different commands on
command line
• Thousands of command will be there. Is it a good idea to put all these
commands in the shell program?
• What if you want to run a program from shell that is not present in
shell program? ( Running your C program )
• The shell program typically uses fork() to create a new child process
and asks the child process to run the command.
EXEC(), WAIT() AND EXIT() SYSTEM CALLS
What each system call does?
• exec() – loads a new program into the main memory and executes it.
• A process exits or terminates using exit() system call. The resources
like memory/cpu of the process are set free.
• return status statement from main function = exit(status)
• PCB of the process is still present in memory
• wait() – the parent waits for the completion of the child process.
Parent enters the wait state.
• The parent may be interested in knowing about the status of the
child.
• After getting the status, the parent asks the kernel to clean up the
PCB of child process.
What happens if the parent doesn’t wait for
the child process?
• The process control block of the child remains in the process table
evens after it has terminated using exit().
• These processes are called zombie process - process has terminated
but PCB is still there in process table.
• Once the parent terminates, these zombie process also becomes an
orphan process.
• No parent + PCB still in the process table after terminating
SIDE EFFECTS OF ZOMBIE PROCESS
while(1) {
fork();
}
• Fork bomb
• Number of PIDs is limited in the operating system. Once all PIDs are
taken by the zombie process, no new process can be created.
• Since no new process can be created, one cannot even run a
command on the command line.
• The only option to recover from a fork() bomb is to reboot the
system.
Orphan Process
• A process which doesn’t have a parent process is called an orphan
process.
• This may happen if the parent process terminates before child
completes.
• What happens to the orphan process?
• Orphan process gets reparented and the new parent is the INIT
process in most cases.
• The new parent then waits for the child to complete and then asks
the kernel to clean the PCB.
ZOMBIE PROCESS PROGRAM
ORPHAN PROCESS PROGRAM
References
• https://shivammitra.com/operating%20system/zombie-and-orphan-
process-in-opearting-system
• Zombie and orphan process video - https://youtu.be/L3YQDUuDjoo
• https://shivammitra.com/operating%20system/fork-exec-wait-in-
operating-system/

More Related Content

What's hot

What's hot (20)

Os unit 3 , process management
Os unit 3 , process managementOs unit 3 , process management
Os unit 3 , process management
 
Process management os concept
Process management os conceptProcess management os concept
Process management os concept
 
Process state in OS
Process state in OSProcess state in OS
Process state in OS
 
Process of operating system
Process of operating systemProcess of operating system
Process of operating system
 
Operating System-Process Scheduling
Operating System-Process SchedulingOperating System-Process Scheduling
Operating System-Process Scheduling
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
 
Process management in os
Process management in osProcess management in os
Process management in os
 
SCHEDULING ALGORITHMS
SCHEDULING ALGORITHMSSCHEDULING ALGORITHMS
SCHEDULING ALGORITHMS
 
Round Robin Scheduling Algorithm
Round Robin Scheduling AlgorithmRound Robin Scheduling Algorithm
Round Robin Scheduling Algorithm
 
Process concept
Process conceptProcess concept
Process concept
 
Processes and threads
Processes and threadsProcesses and threads
Processes and threads
 
Process in operating system
Process in operating systemProcess in operating system
Process in operating system
 
Process control block(PCB)
Process control block(PCB)Process control block(PCB)
Process control block(PCB)
 
System call (Fork +Exec)
System call (Fork +Exec)System call (Fork +Exec)
System call (Fork +Exec)
 
Cpu scheduling in operating System.
Cpu scheduling in operating System.Cpu scheduling in operating System.
Cpu scheduling in operating System.
 
Operating system critical section
Operating system   critical sectionOperating system   critical section
Operating system critical section
 
Operations on Processes and Cooperating processes
Operations on Processes and Cooperating processesOperations on Processes and Cooperating processes
Operations on Processes and Cooperating processes
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 
Deadlock
DeadlockDeadlock
Deadlock
 
CPU Scheduling algorithms
CPU Scheduling algorithmsCPU Scheduling algorithms
CPU Scheduling algorithms
 

Similar to Process management in operating system | process states | PCB | FORK() | Zombie and Orphan process

Processes, Threads.pptx
Processes, Threads.pptxProcesses, Threads.pptx
Processes, Threads.pptxLECO9
 
Processes, Threads.pptx
Processes, Threads.pptxProcesses, Threads.pptx
Processes, Threads.pptxSKUP1
 
Chapter -2 operating system presentation
Chapter -2 operating system presentationChapter -2 operating system presentation
Chapter -2 operating system presentationchnrketan
 
Systems Programming Assignment Help - Processes
Systems Programming Assignment Help - ProcessesSystems Programming Assignment Help - Processes
Systems Programming Assignment Help - ProcessesHelpWithAssignment.com
 
Basic concept of process
Basic concept of processBasic concept of process
Basic concept of processNabin Dahal
 
04_ForkPipe.pptx
04_ForkPipe.pptx04_ForkPipe.pptx
04_ForkPipe.pptxvnwzympx
 
Operating system 18 process creation and termination
Operating system 18 process creation and terminationOperating system 18 process creation and termination
Operating system 18 process creation and terminationVaibhav Khanna
 
Lecture_3-Process Management.pdf
Lecture_3-Process Management.pdfLecture_3-Process Management.pdf
Lecture_3-Process Management.pdfHarika Pudugosula
 
Operating Systems 1 (6/12) - Processes
Operating Systems 1 (6/12) - ProcessesOperating Systems 1 (6/12) - Processes
Operating Systems 1 (6/12) - ProcessesPeter Tröger
 
Process Management.pdf
Process Management.pdfProcess Management.pdf
Process Management.pdfYashjangid9
 

Similar to Process management in operating system | process states | PCB | FORK() | Zombie and Orphan process (20)

Processes, Threads.pptx
Processes, Threads.pptxProcesses, Threads.pptx
Processes, Threads.pptx
 
Processes, Threads.pptx
Processes, Threads.pptxProcesses, Threads.pptx
Processes, Threads.pptx
 
Lect3 process
Lect3 processLect3 process
Lect3 process
 
Chapter -2 operating system presentation
Chapter -2 operating system presentationChapter -2 operating system presentation
Chapter -2 operating system presentation
 
Lecture 2 process
Lecture 2   processLecture 2   process
Lecture 2 process
 
Systems Programming Assignment Help - Processes
Systems Programming Assignment Help - ProcessesSystems Programming Assignment Help - Processes
Systems Programming Assignment Help - Processes
 
9 cm402.13
9 cm402.139 cm402.13
9 cm402.13
 
Basic concept of process
Basic concept of processBasic concept of process
Basic concept of process
 
04_ForkPipe.pptx
04_ForkPipe.pptx04_ForkPipe.pptx
04_ForkPipe.pptx
 
Os lectures
Os lecturesOs lectures
Os lectures
 
3 process management
3 process management3 process management
3 process management
 
Lecture5
Lecture5Lecture5
Lecture5
 
Operating system 18 process creation and termination
Operating system 18 process creation and terminationOperating system 18 process creation and termination
Operating system 18 process creation and termination
 
Lecture_3-Process Management.pdf
Lecture_3-Process Management.pdfLecture_3-Process Management.pdf
Lecture_3-Process Management.pdf
 
Processes
ProcessesProcesses
Processes
 
Ch3 processes
Ch3   processesCh3   processes
Ch3 processes
 
Process management
Process managementProcess management
Process management
 
OS (1).pptx
OS (1).pptxOS (1).pptx
OS (1).pptx
 
Operating Systems 1 (6/12) - Processes
Operating Systems 1 (6/12) - ProcessesOperating Systems 1 (6/12) - Processes
Operating Systems 1 (6/12) - Processes
 
Process Management.pdf
Process Management.pdfProcess Management.pdf
Process Management.pdf
 

More from Shivam Mitra

Preparing for SRE Interviews
Preparing for SRE InterviewsPreparing for SRE Interviews
Preparing for SRE InterviewsShivam Mitra
 
PART 4 - Python Tutorial | If Else In Python With Examples
PART 4 - Python Tutorial | If Else In Python With ExamplesPART 4 - Python Tutorial | If Else In Python With Examples
PART 4 - Python Tutorial | If Else In Python With ExamplesShivam Mitra
 
PART 3 - Python Tutorial | For Loop In Python With Examples
PART 3 - Python Tutorial | For Loop In Python With ExamplesPART 3 - Python Tutorial | For Loop In Python With Examples
PART 3 - Python Tutorial | For Loop In Python With ExamplesShivam Mitra
 
PART 9 - Python Tutorial | While Loop In Python With Examples
PART 9 - Python Tutorial | While Loop In Python With ExamplesPART 9 - Python Tutorial | While Loop In Python With Examples
PART 9 - Python Tutorial | While Loop In Python With ExamplesShivam Mitra
 
PART 8 - Python Tutorial | User Input In Python With Examples
PART 8 - Python Tutorial | User Input In Python With ExamplesPART 8 - Python Tutorial | User Input In Python With Examples
PART 8 - Python Tutorial | User Input In Python With ExamplesShivam Mitra
 
PART 6 - Python Tutorial | Tuples In Python With Examples
PART 6 - Python Tutorial | Tuples In Python With ExamplesPART 6 - Python Tutorial | Tuples In Python With Examples
PART 6 - Python Tutorial | Tuples In Python With ExamplesShivam Mitra
 
PART 10 - Python Tutorial | Functions In Python With Examples
PART 10 - Python Tutorial | Functions In Python With ExamplesPART 10 - Python Tutorial | Functions In Python With Examples
PART 10 - Python Tutorial | Functions In Python With ExamplesShivam Mitra
 
PART 7 - Python Tutorial | Dictionaries In Python With Examples
PART 7 - Python Tutorial | Dictionaries In Python With ExamplesPART 7 - Python Tutorial | Dictionaries In Python With Examples
PART 7 - Python Tutorial | Dictionaries In Python With ExamplesShivam Mitra
 
PART 0 - Python Tutorial | Why should you learn python
PART 0 - Python Tutorial | Why should you learn pythonPART 0 - Python Tutorial | Why should you learn python
PART 0 - Python Tutorial | Why should you learn pythonShivam Mitra
 
PART 1 - Python Tutorial | Variables and Data Types in Python
PART 1 - Python Tutorial | Variables and Data Types in PythonPART 1 - Python Tutorial | Variables and Data Types in Python
PART 1 - Python Tutorial | Variables and Data Types in PythonShivam Mitra
 
Part 2 - Python Tutorial | Introduction to Lists
Part 2 - Python Tutorial | Introduction to ListsPart 2 - Python Tutorial | Introduction to Lists
Part 2 - Python Tutorial | Introduction to ListsShivam Mitra
 
Process Synchronization in operating system | mutex | semaphore | race condition
Process Synchronization in operating system | mutex | semaphore | race conditionProcess Synchronization in operating system | mutex | semaphore | race condition
Process Synchronization in operating system | mutex | semaphore | race conditionShivam Mitra
 
What is Internet and How it Works
What is Internet and How it WorksWhat is Internet and How it Works
What is Internet and How it WorksShivam Mitra
 
OSI Model Layers and Internet Protocol Stack
OSI Model Layers and Internet Protocol StackOSI Model Layers and Internet Protocol Stack
OSI Model Layers and Internet Protocol StackShivam Mitra
 
Basics of Stock Market
Basics of Stock MarketBasics of Stock Market
Basics of Stock MarketShivam Mitra
 
Assets vs liability
Assets vs liabilityAssets vs liability
Assets vs liabilityShivam Mitra
 
Pycricbuzz - a python library to fetch live cricket scores
Pycricbuzz -  a python library to fetch live cricket scoresPycricbuzz -  a python library to fetch live cricket scores
Pycricbuzz - a python library to fetch live cricket scoresShivam Mitra
 

More from Shivam Mitra (17)

Preparing for SRE Interviews
Preparing for SRE InterviewsPreparing for SRE Interviews
Preparing for SRE Interviews
 
PART 4 - Python Tutorial | If Else In Python With Examples
PART 4 - Python Tutorial | If Else In Python With ExamplesPART 4 - Python Tutorial | If Else In Python With Examples
PART 4 - Python Tutorial | If Else In Python With Examples
 
PART 3 - Python Tutorial | For Loop In Python With Examples
PART 3 - Python Tutorial | For Loop In Python With ExamplesPART 3 - Python Tutorial | For Loop In Python With Examples
PART 3 - Python Tutorial | For Loop In Python With Examples
 
PART 9 - Python Tutorial | While Loop In Python With Examples
PART 9 - Python Tutorial | While Loop In Python With ExamplesPART 9 - Python Tutorial | While Loop In Python With Examples
PART 9 - Python Tutorial | While Loop In Python With Examples
 
PART 8 - Python Tutorial | User Input In Python With Examples
PART 8 - Python Tutorial | User Input In Python With ExamplesPART 8 - Python Tutorial | User Input In Python With Examples
PART 8 - Python Tutorial | User Input In Python With Examples
 
PART 6 - Python Tutorial | Tuples In Python With Examples
PART 6 - Python Tutorial | Tuples In Python With ExamplesPART 6 - Python Tutorial | Tuples In Python With Examples
PART 6 - Python Tutorial | Tuples In Python With Examples
 
PART 10 - Python Tutorial | Functions In Python With Examples
PART 10 - Python Tutorial | Functions In Python With ExamplesPART 10 - Python Tutorial | Functions In Python With Examples
PART 10 - Python Tutorial | Functions In Python With Examples
 
PART 7 - Python Tutorial | Dictionaries In Python With Examples
PART 7 - Python Tutorial | Dictionaries In Python With ExamplesPART 7 - Python Tutorial | Dictionaries In Python With Examples
PART 7 - Python Tutorial | Dictionaries In Python With Examples
 
PART 0 - Python Tutorial | Why should you learn python
PART 0 - Python Tutorial | Why should you learn pythonPART 0 - Python Tutorial | Why should you learn python
PART 0 - Python Tutorial | Why should you learn python
 
PART 1 - Python Tutorial | Variables and Data Types in Python
PART 1 - Python Tutorial | Variables and Data Types in PythonPART 1 - Python Tutorial | Variables and Data Types in Python
PART 1 - Python Tutorial | Variables and Data Types in Python
 
Part 2 - Python Tutorial | Introduction to Lists
Part 2 - Python Tutorial | Introduction to ListsPart 2 - Python Tutorial | Introduction to Lists
Part 2 - Python Tutorial | Introduction to Lists
 
Process Synchronization in operating system | mutex | semaphore | race condition
Process Synchronization in operating system | mutex | semaphore | race conditionProcess Synchronization in operating system | mutex | semaphore | race condition
Process Synchronization in operating system | mutex | semaphore | race condition
 
What is Internet and How it Works
What is Internet and How it WorksWhat is Internet and How it Works
What is Internet and How it Works
 
OSI Model Layers and Internet Protocol Stack
OSI Model Layers and Internet Protocol StackOSI Model Layers and Internet Protocol Stack
OSI Model Layers and Internet Protocol Stack
 
Basics of Stock Market
Basics of Stock MarketBasics of Stock Market
Basics of Stock Market
 
Assets vs liability
Assets vs liabilityAssets vs liability
Assets vs liability
 
Pycricbuzz - a python library to fetch live cricket scores
Pycricbuzz -  a python library to fetch live cricket scoresPycricbuzz -  a python library to fetch live cricket scores
Pycricbuzz - a python library to fetch live cricket scores
 

Recently uploaded

Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 

Recently uploaded (20)

Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 

Process management in operating system | process states | PCB | FORK() | Zombie and Orphan process

  • 2. PREVIOUS VIDEO • Introduction to operating system • Kernel vs operating system • Functions of operating system • Examples of operating system and kernel • System calls • Interrupts • Video Link + telegram link + form link in the description
  • 3. AGENDA • Program VS process • Process control block • Process states • Process creation through fork() • Exec(), wait() and exit() system calls • Zombie and orphan process
  • 4. INTERVIEW QUESTIONS • Difference between a program and a process • Which data structure is used to represent a process? • List some important fields in Process Control Block • What is INIT process in Linux? • What are the different states of a process? Explain with process state diagram. • How will you create a new process in Linux? • How does a parent process differ from a child process? • Number of processes created with N fork() calls?
  • 5. INTERVIEW QUESTIONS CONTINUED • What is the use of exec(), wait() and exit() system calls? • What happens if parent doesn’t wait for its child process? • Give some real world examples where fork(), exec() and wait() system calls are used? • What is zombie process? What are the side effects of zombie processes? • What is an orphan process? How it differs from zombie process? • Give examples of zombie and orphan process.
  • 6. PROGRAM VS PROCESS • Program – An executable file that is stored on the hard disk or a secondary memory • When you execute this file either by double clicking or from command line, it becomes a process • Program – Passive entity • Process – Active entity • Process memory = stack + data + heap + text • Program is just the text section of memory • Process is text section + a lot of other attributes
  • 7. What are other attributes of a process? • Program counter(PC) – Address of next instruction to be executed on CPU • Process states – new, ready, running, waiting etc. • CPU registers – value of CPU registers are stored when context switch happens • List of open files that the process is using for reading and writing • Process priority – Used in process scheduling • Process ID – unique identifier for each process • Parent process ID – Process ID of parent process • Memory information – stack, heap, data, text
  • 8. PROCESS CONTROL BLOCK • These all attributes or information about a process are stored in a data structure called Process Control Block(PCB). • Struct task_struct { pid_t pid; long state; int priority; struct task_struct *parent; struct files_struct *files; struct mm_struct *mm; long program_counter; . . } • Video: https://youtu.be/x2JIEgAVkTI
  • 9. PROCESS STATES • Batch operating system in old times • Jobs were submitted in batches • Jobs were first stored in job queue on disk • Not all job can fit in main memory • Selected jobs were loaded into main memory by long term scheduler • These were kept in ready queue and scheduled by CPU scheduler or short term scheduler • Video: https://youtu.be/mhKr6Dnf2fA
  • 11. WHAT EACH STATE MEANS? • NEW • BATCH OS – Job arrived in the job queue • Time sharing OS – process is being created • READY – Process waiting in ready queue for being assigned to a CPU/processor • RUNNING – Program is being executed on the CPU • WAITING – Process is waiting for some event to occur (I/O) • TERMINATED – Process has finished its execution.
  • 12.
  • 13. WHEN DOES TRANSITION FROM RUNNING TO READY HAPPENS? • A hardware interrupt happens on the CPU • A higher priority process arrives in the ready queue (preemptive scheduling) • Time slice of the process expires (Round robin scheduling)
  • 14. • Program – helloworld.c • Compile – gcc helloworld.c • Executable – a.out • Execute the program • a.out is bought to RAM from disk • A PCB is created (PC -> address of first instruction ) • Enters ready queue • CPU scheduler schedules it on CPU • Running state • CPU starts executing • I/O – enters waiting state • Time slice expires – ready state • Terminated
  • 15. INIT PROCESS • First process that is started during booting of the system • PID – 1 • This process keeps on running forever until you shut down. • All other processes are either direct or indirect children of INIT process. • Pstree –p command to view the process tree on linux
  • 16. PROCESS CREATION USING FORK • CreateProcess() in Windows • Fork() creates a new child process that is a copy of the parent process • In what ways the child process differs from parent? • PID • Parent PID • File locks • Process utilization info • In what ways they are similar? • Program counter • Memory ( unless fork() is followed by exec() ) • CPU registers • priority
  • 17. WHAT HAPPENS AFTER FORK() IS CALLED? • Execution – Both process starts executing from the next line after fork() • Memory – stack, heap, text and data segment are duplicated for the child process. • Copy on write is used in modern implementation of fork. • Copy the memory only when a write is being made to a memory page. • In most cases, fork() is followed by exec(). • Copy on write saves expensive recopying of memory
  • 18. FORK CALL RETURN VALUES • How do you differentiate between the the parent process and the child process? • Fork() returns PID of the child process to parent • Fork() returns 0 to the child process • Fork() returns -1 if there is any error • Videos • https://youtu.be/FXAvkNY1dGQ • https://youtu.be/AyZeHBPKdMs
  • 20.
  • 21. How may child processes? fork(); fork(); Video: https://youtu.be/iZa2vm7A6mw
  • 22. What if you want the child to run another program? • Shell program which helps in running different commands on command line • Thousands of command will be there. Is it a good idea to put all these commands in the shell program? • What if you want to run a program from shell that is not present in shell program? ( Running your C program ) • The shell program typically uses fork() to create a new child process and asks the child process to run the command.
  • 23. EXEC(), WAIT() AND EXIT() SYSTEM CALLS
  • 24. What each system call does? • exec() – loads a new program into the main memory and executes it. • A process exits or terminates using exit() system call. The resources like memory/cpu of the process are set free. • return status statement from main function = exit(status) • PCB of the process is still present in memory • wait() – the parent waits for the completion of the child process. Parent enters the wait state. • The parent may be interested in knowing about the status of the child. • After getting the status, the parent asks the kernel to clean up the PCB of child process.
  • 25.
  • 26. What happens if the parent doesn’t wait for the child process? • The process control block of the child remains in the process table evens after it has terminated using exit(). • These processes are called zombie process - process has terminated but PCB is still there in process table. • Once the parent terminates, these zombie process also becomes an orphan process. • No parent + PCB still in the process table after terminating
  • 27. SIDE EFFECTS OF ZOMBIE PROCESS while(1) { fork(); } • Fork bomb • Number of PIDs is limited in the operating system. Once all PIDs are taken by the zombie process, no new process can be created. • Since no new process can be created, one cannot even run a command on the command line. • The only option to recover from a fork() bomb is to reboot the system.
  • 28. Orphan Process • A process which doesn’t have a parent process is called an orphan process. • This may happen if the parent process terminates before child completes. • What happens to the orphan process? • Orphan process gets reparented and the new parent is the INIT process in most cases. • The new parent then waits for the child to complete and then asks the kernel to clean the PCB.
  • 31. References • https://shivammitra.com/operating%20system/zombie-and-orphan- process-in-opearting-system • Zombie and orphan process video - https://youtu.be/L3YQDUuDjoo • https://shivammitra.com/operating%20system/fork-exec-wait-in- operating-system/