Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Aptitude
  • Engineering Mathematics
  • Discrete Mathematics
  • Operating System
  • DBMS
  • Computer Networks
  • Digital Logic and Design
  • C Programming
  • Data Structures
  • Algorithms
  • Theory of Computation
  • Compiler Design
  • Computer Org and Architecture
Open In App
Next Article:
Process Creation and Deletions in Operating Systems
Next article icon

Process Creation and Deletions in Operating Systems

Last Updated : 31 Dec, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

A process is an instance of a program running, and its lifecycle includes various stages such as creation, execution, and deletion.

  • The operating system handles process creation by allocating necessary resources and assigning each process a unique identifier.
  • Process deletion involves releasing resources once a process completes its execution.
  • Processes are often organized in a hierarchy, where parent processes create child processes, forming a tree-like structure.

Process Creation

As discussed above, processes in most of the operating systems (both Windows and Linux) form hierarchy. So a new process is always created by a parent process. The process that creates the new one is called the parent process, and the newly created process is called the child process. A process can create multiple new processes while it’s running by using system calls to create them.

1. When a new process is created, the operating system assigns a unique Process Identifier (PID) to it and inserts a new entry in the primary process table. 
2. Then required memory space for all the elements of the process such as program, data, and stack is allocated including space for its Process Control Block (PCB). 
3. Next, the various values in PCB are initialized such as, 

  1. The process identification part is filled with PID assigned to it in step (1) and also its parent's PID.
  2. The processor register values are mostly filled with zeroes, except for the stack pointer and program counter. The stack pointer is filled with the address of the stack-allocated to it in step (2) and the program counter is filled with the address of its program entry point.
  3. The process state information would be set to 'New'.
  4. Priority would be lowest by default, but the user can specify any priority during creation. Then the operating system will link this process to the scheduling queue and the process state would be changed from 'New' to 'Ready'. Now the process is competing for the CPU. 
  5. Additionally, the operating system will create some other data structures such as log files or accounting files to keep track of process activity.

Understanding System Calls for Process Creation in UNIX Operating System:

Process creation is achieved through the fork() system call. The new process that gets created is called the child process, and the one that started it (the one that was already running) is called the parent process. After the fork() call, you end up with two processes: the parent and the child, both running independently.

  • The fork() system call creates a copy of the current process, including all its resources, but with just one thread.
  • The exec() system call replaces the current process's memory with the code and data from a specified executable file. It doesn’t return; instead, it "transfers" the process to the new program.
  • The waitpid() function makes the parent process wait until a specific child process finishes executing.
unix_process_creation
Process creation in Unix

Example:
int pid = fork();
if (pid == 0)
{
/* Child process */
exec("foo");
}
else
{
/* Parent process */
waitpid(pid, &status, options);
}

Understanding System Calls for Process Creation in Windows Operating System:

In Windows, the system call used for process creation is CreateProcess(). This function is responsible for creating a new process, initializing its memory, and loading the specified program into the process's address space.

  • CreateProcess() in Windows combines the functionality of both UNIX's fork() and exec(). It creates a new process with its own memory space rather than duplicating the parent process like fork() does. It also allows specifying which program to run, similar to how exec() works in UNIX.
  • When you use CreateProcess(), you need to provide some extra details to handle any changes between the parent and child processes. These details control things like the process’s environment, security settings, and how the child process works with the parent or other processes. It gives you more control and flexibility compared to the UNIX system.

Process Deletion 

Processes terminate themselves when they finish executing their last statement, after which the operating system uses the exit() system call to delete their context. Then all the resources held by that process like physical and virtual memory, 10 buffers, open files, etc., are taken back by the operating system. A process P can be terminated either by the operating system or by the parent process of P. 

A parent may terminate a process due to one of the following reasons:

  1. When task given to the child is not required now.
  2. When the child has taken more resources than its limit.
  3. The parent of the process is exiting, as a result, all its children are deleted. This is called cascaded termination.

A process can be terminated/deleted in many ways. Some of the ways are:

  1. Normal termination: The process completes its task and calls an exit() system call. The operating system cleans up the resources used by the process and removes it from the process table.
  2. Abnormal termination/Error exit: A process may terminate abnormally if it encounters an error or needs to stop immediately. This can happen through the abort() system call.
  3. Termination by parent process: A parent process may terminate a child process when the child finishes its task. This is done by the using kill() system call.
  4. Termination by signal: The parent process can also send specific signals like SIGSTOP to pause the child or SIGKILL to immediately terminate it.

Conclusion

Processes are created using system calls like fork() in UNIX or CreateProcess() in Windows, which handle the allocation of resources, assignment of unique identifiers, and initialization of the process control block. Once a process completes its task, it can terminate through various methods, such as normal termination, abnormal termination, or by the parent process using system calls like exit(), abort(), or kill().


Next Article
Process Creation and Deletions in Operating Systems

S

ShivaTeja2
Improve
Article Tags :
  • Operating Systems
  • GATE CS

Similar Reads

    Cooperating Process in Operating System
    Pre-requisites: Process Synchronization In an operating system, everything is around the process. How the process goes through several different states. So in this article, we are going to discuss one type of process called as Cooperating Process. In the operating system there are two types of proce
    2 min read
    Design and Implementation in Operating System
    The design of an operating system is a broad and complex topic that touches on many aspects of computer science. This article will cover the design of operating systems in general and then focus on the implementation aspect. Design Goals:Design goals are the objectives of the operating system. They
    6 min read
    5 State Process Model in Operating System
    In an operating system (OS), managing how programs run and interact with system resources is crucial for efficient performance. The 5-state process model is a fundamental framework used by OSs to categorize and control the behavior of processes, which are individual instances of programs running on
    6 min read
    States of a Process in Operating Systems
    In an operating system, a process is a program that is being executed. During its execution, a process goes through different states. Understanding these states helps us see how the operating system manages processes, ensuring that the computer runs efficiently. Please refer Process in Operating Sys
    11 min read
    Process in Operating System
    A process is a program in execution. For example, when we write a program in C or C++ and compile it, the compiler creates binary code. The original code and binary code are both programs. When we actually run the binary code, it becomes a process. A process is an 'active' entity instead of a progra
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences