SlideShare a Scribd company logo
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

Deadlock
DeadlockDeadlock
Deadlock
Rajandeep Gill
 
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
Shivam Mitra
 
Multi processor scheduling
Multi  processor schedulingMulti  processor scheduling
Multi processor scheduling
Shashank Kapoor
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
Kumar Pritam
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process Concepts
Mukesh Chinta
 
Kernel. Operating System
Kernel. Operating SystemKernel. Operating System
Kernel. Operating System
pratikkadam78
 
Ch4 memory management
Ch4 memory managementCh4 memory management
Ch4 memory management
Bullz Musetsho
 
Operating systems system structures
Operating systems   system structuresOperating systems   system structures
Operating systems system structures
Mukesh Chinta
 
CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2
Kathirvel Ayyaswamy
 
deadlock detection using Goldman's algorithm by ANIKET CHOUDHURY
deadlock detection using Goldman's algorithm by ANIKET CHOUDHURYdeadlock detection using Goldman's algorithm by ANIKET CHOUDHURY
deadlock detection using Goldman's algorithm by ANIKET CHOUDHURY
अनिकेत चौधरी
 
CPU Scheduling in OS Presentation
CPU Scheduling in OS  PresentationCPU Scheduling in OS  Presentation
CPU Scheduling in OS Presentation
usmankiyani1
 
Os unit 3 , process management
Os unit 3 , process managementOs unit 3 , process management
Os unit 3 , process management
Arnav Chowdhury
 
Operating system services 9
Operating system services 9Operating system services 9
Operating system services 9
myrajendra
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
Prakhar Maurya
 
17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria 17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria
myrajendra
 
SCHEDULING ALGORITHMS
SCHEDULING ALGORITHMSSCHEDULING ALGORITHMS
SCHEDULING ALGORITHMS
Dhaval Sakhiya
 
Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OS
MsAnita2
 
Dead Lock in operating system
Dead Lock in operating systemDead Lock in operating system
Dead Lock in operating system
Ali Haider
 
Process scheduling algorithms
Process scheduling algorithmsProcess scheduling algorithms
Process scheduling algorithms
Shubham Sharma
 
Operating system - Process and its concepts
Operating system - Process and its conceptsOperating system - Process and its concepts
Operating system - Process and its concepts
Karan Thakkar
 

What's hot (20)

Deadlock
DeadlockDeadlock
Deadlock
 
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
 
Multi processor scheduling
Multi  processor schedulingMulti  processor scheduling
Multi processor scheduling
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process Concepts
 
Kernel. Operating System
Kernel. Operating SystemKernel. Operating System
Kernel. Operating System
 
Ch4 memory management
Ch4 memory managementCh4 memory management
Ch4 memory management
 
Operating systems system structures
Operating systems   system structuresOperating systems   system structures
Operating systems system structures
 
CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2
 
deadlock detection using Goldman's algorithm by ANIKET CHOUDHURY
deadlock detection using Goldman's algorithm by ANIKET CHOUDHURYdeadlock detection using Goldman's algorithm by ANIKET CHOUDHURY
deadlock detection using Goldman's algorithm by ANIKET CHOUDHURY
 
CPU Scheduling in OS Presentation
CPU Scheduling in OS  PresentationCPU Scheduling in OS  Presentation
CPU Scheduling in OS Presentation
 
Os unit 3 , process management
Os unit 3 , process managementOs unit 3 , process management
Os unit 3 , process management
 
Operating system services 9
Operating system services 9Operating system services 9
Operating system services 9
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
 
17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria 17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria
 
SCHEDULING ALGORITHMS
SCHEDULING ALGORITHMSSCHEDULING ALGORITHMS
SCHEDULING ALGORITHMS
 
Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OS
 
Dead Lock in operating system
Dead Lock in operating systemDead Lock in operating system
Dead Lock in operating system
 
Process scheduling algorithms
Process scheduling algorithmsProcess scheduling algorithms
Process scheduling algorithms
 
Operating system - Process and its concepts
Operating system - Process and its conceptsOperating system - Process and its concepts
Operating system - Process and its concepts
 

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.pptx
LECO9
 
Processes, Threads.pptx
Processes, Threads.pptxProcesses, Threads.pptx
Processes, Threads.pptx
SKUP1
 
Lect3 process
Lect3 processLect3 process
Lect3 process
santosh rao
 
Chapter -2 operating system presentation
Chapter -2 operating system presentationChapter -2 operating system presentation
Chapter -2 operating system presentation
chnrketan
 
Lecture 2 process
Lecture 2   processLecture 2   process
Lecture 2 process
Kumbirai Junior Muzavazi
 
Systems Programming Assignment Help - Processes
Systems Programming Assignment Help - ProcessesSystems Programming Assignment Help - Processes
Systems Programming Assignment Help - Processes
HelpWithAssignment.com
 
9 cm402.13
9 cm402.139 cm402.13
9 cm402.13
myrajendra
 
Process of operating system
Process of operating systemProcess of operating system
Basic concept of process
Basic concept of processBasic concept of process
Basic concept of process
Nabin Dahal
 
04_ForkPipe.pptx
04_ForkPipe.pptx04_ForkPipe.pptx
04_ForkPipe.pptx
vnwzympx
 
Os lectures
Os lecturesOs lectures
Os lectures
Adnan Ghafoor
 
3 process management
3 process management3 process management
3 process management
Dr. Loganathan R
 
Lecture5
Lecture5Lecture5
Lecture5
Ali Shah
 
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
Vaibhav Khanna
 
Lecture_3-Process Management.pdf
Lecture_3-Process Management.pdfLecture_3-Process Management.pdf
Lecture_3-Process Management.pdf
Harika Pudugosula
 
Processes
ProcessesProcesses
Processes
RaviRaj339
 
Ch3 processes
Ch3   processesCh3   processes
Ch3 processes
Welly Dian Astika
 
Process management
Process managementProcess management
Process management
Akshay Ithape
 
OS (1).pptx
OS (1).pptxOS (1).pptx
OS (1).pptx
KumarMit2
 
Operating Systems 1 (6/12) - Processes
Operating Systems 1 (6/12) - ProcessesOperating Systems 1 (6/12) - Processes
Operating Systems 1 (6/12) - Processes
Peter Tröger
 

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
 
Process of operating system
Process of operating systemProcess of operating system
Process of operating system
 
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
 

More from Shivam Mitra

Preparing for SRE Interviews
Preparing for SRE InterviewsPreparing for SRE Interviews
Preparing for SRE Interviews
Shivam 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 Examples
Shivam 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 Examples
Shivam 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 Examples
Shivam 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 Examples
Shivam 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 Examples
Shivam 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 Examples
Shivam 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 Examples
Shivam 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 python
Shivam 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 Python
Shivam 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 Lists
Shivam Mitra
 
Process Scheduling Algorithms | Interviews | Operating system
Process Scheduling Algorithms | Interviews | Operating systemProcess Scheduling Algorithms | Interviews | Operating system
Process Scheduling Algorithms | Interviews | Operating system
Shivam 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 Works
Shivam 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 Stack
Shivam Mitra
 
Basics of Stock Market
Basics of Stock MarketBasics of Stock Market
Basics of Stock Market
Shivam Mitra
 
Assets vs liability
Assets vs liabilityAssets vs liability
Assets vs liability
Shivam 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 scores
Shivam 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 Scheduling Algorithms | Interviews | Operating system
Process Scheduling Algorithms | Interviews | Operating systemProcess Scheduling Algorithms | Interviews | Operating system
Process Scheduling Algorithms | Interviews | Operating system
 
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

Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
mamamaam477
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
HODECEDSIET
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
mahammadsalmanmech
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
KrishnaveniKrishnara1
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
sachin chaurasia
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
Yasser Mahgoub
 
Casting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdfCasting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdf
zubairahmad848137
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
RadiNasr
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
Recycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part IIRecycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part II
Aditya Rajan Patra
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 

Recently uploaded (20)

Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
 
Casting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdfCasting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdf
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
Recycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part IIRecycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part II
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 

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/