Table of Contents
Parent Process
UNIX" >UNIX
Solution and Prevention" >Solution and Prevention
Home Operation and Maintenance Linux Operation and Maintenance What are parent process and child process

What are parent process and child process

Jun 22, 2017 pm 03:41 PM
process

Parent Process

In the computer field, the parent process (English: Parent Process) refers to a process that has created one or more child processes.

UNIX


##In UNIX, except for

process 0 (i.e. PID =0 swap process, all processes except Swapper Process) are created by other processes using the system call fork. Here, the process that calls fork to create a new process is the parent process, and the corresponding The created process is a child process, so processes other than process 0 have only one parent process, but a process can have multiple child processes.

The operating system kernel uses the process identifier (

Process Identifier, PID) to identify the process. Process 0 is a special process created when the system boots. After it calls fork to create a child process (that is, process 1 with PID=1, also called init), process 0 becomes a swap process (sometimes also called Idle process), and process 1 (init process) is the ancestor of all other processes in the system.

Zombie process and orphan process


When a child process ends running (usually calling

exit, a fatal error occurs during running, or When a termination signal is received), the exit status (return value) of the child process will be reported to the operating system, and the system will use the SIGCHLD signal to notify the parent process of the termination of the child process. At this time, the process control block (PCB) of the child process ) still resides in memory. Generally speaking, after receiving SIGCHLD, the parent process will use the wait system call to obtain the exit status of the child process, and then the kernel can release the PCB of the ended child process from memory; if the parent process does not do this, the child process will The PCB of the process will always reside in the memory, which means it becomes a zombie process.

Orphan processes refer to child processes that are still running after the parent process ends. In UNIX-like systems, orphan processes are generally "adopted" by the init process and become init's child processes.

In order to avoid the generation of zombie processes, the method generally adopted in practical applications is:

  1. Set the SIGCHLD signal processing function in the parent process to SIG_IGN (ignore the signal) ;

  2. Fork twice and kill the first-level child process, making the second-level child process an orphan process and "adopted" and cleaned up by init.

Linux

In the Linux kernel, there is a very slight difference between a process and a POSIX thread, and the definition of a parent process is also different from that of UNIX . Linux has two kinds of parent processes, namely (formal) parent process and actual parent process. For a child process, its parent process is the process that receives the SIGCHLD signal when the child process ends, and the actual parent process is the process that receives the SIGCHLD signal when the child process ends. The process that actually creates the child process in the thread environment. For a normal process, the parent process and the actual parent process are the same process, but for a POSIX thread that exists in the form of a process, the parent process and the actual parent process may be different.

Child process


#In the computer field, a child process is created by another process (correspondingly called the parent process) created process. The child process inherits most of the attributes of the parent process, such as file descriptors.

produces


In Unix, the child process is usually the system call

fork## The product of #. In this case, the child process starts as a copy of the parent process, and after that, depending on specific needs, the child process can chain load another process with the help of exec calls. A program.

Relationship with the parent process

A process may have multiple child processes, but there can only be one at most. Parent process, and if a process does not have a parent process, it can be seen that the process is likely to be directly generated by the kernel. In Unix and Unix-like systems, the process with process ID 1 (i.e. init process) is directly created by the kernel during the system boot phase and will not terminate execution during the system running (see
Linux startup process) ; For other processes that have no parent process, they may be executed to complete various background tasks in user space.

When a child process ends, is interrupted, or resumes execution, the kernel will send the SIGCHLD signal to its parent process. By default, the parent process will ignore it with the SIG_IGN function.

"Orphan Process" and "Zombie Process"

After the corresponding parent process ends execution, the process will become an orphan process, but it will Immediately "adopted" by the init process as its child process.

After a child process terminates execution, if its parent process does not call

wait

in advance, the kernel will continue to retain the exit status and other information of the child process so that the parent process can waitGet it. And because in this case, although the child process has been terminated, it is still consuming system resources, so it is also called a zombie process. waitOften called in the SIGCHLD signal processing function.

Solution and Prevention

In the POSIX.1-2001 standard, the parent process can set the SIGCHLD processing function to SIG_IGN (also the default setting), or to SIGCHLD Set the SA_NOCLDWAIT flag so that the kernel can automatically reclaim the resources of terminated child processes. Since Linux 2.6 and FreeBSD 5.0, both kernels support these two methods. However, when it comes to ignoring the SIGCHLD signal, due to the long-standing differences between System V and BSD, calling wait is still the most convenient way to recycle the resources of the derived child process.

The above is the detailed content of What are parent process and child process. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1252
29
C# Tutorial
1226
24
Explain what the explorer.exe process is Explain what the explorer.exe process is Feb 18, 2024 pm 12:11 PM

What process is explorer.exe? When we use the Windows operating system, we often hear the term "explorer.exe". So, are you curious about what this process is? In this article, we will explain in detail what process explorer.exe is and its functions and effects. First of all, explorer.exe is a key process of the Windows operating system. It is responsible for managing and controlling Windows Explorer (Window

What is the process of com surrogate? What is the process of com surrogate? Sep 14, 2022 pm 02:56 PM

"com surrogate" is the process of "C:\Windows\System32\dllhost.exe"; when this process occurs, it usually means that the "COM+" component stops working. This process takes up a lot of space and even does not respond directly. This is because the computer is loading the file icon. Sometimes a problem occurs, causing the computer to become stuck. You can solve the stuck problem in the computer properties settings.

What kind of process is ccsvchst.exe? What kind of process is ccsvchst.exe? Feb 19, 2024 pm 11:33 PM

ccsvchst.exe is a common process file that is part of the Symantec Endpoint Protection (SEP) software, and SEP is an endpoint protection solution developed by the well-known network security company Symantec. As part of the software, ccsvchst.exe is responsible for managing and monitoring SEP-related processes. First, let’s take a look at SymantecEndpointProtection(

How to properly kill zombie processes in Linux How to properly kill zombie processes in Linux Feb 19, 2024 am 10:40 AM

In Linux systems, zombie processes are special processes that have been terminated but still remain in the system. Although zombie processes do not consume many resources, if there are too many, they may cause system resource exhaustion. This article will introduce how to correctly remove zombie processes to ensure the normal operation of the system. 1Linux zombie process After the child process completes its task, if the parent process does not check the status in time, the child process will become a zombie process. The child process is waiting for confirmation from the parent process, and the system will not recycle it until it is completed. Otherwise, the zombie process will continue to hang in the system. To check whether there are zombie processes in the system, you can run the command top to view all running processes and possible zombie processes. The result of the ‘top’ command can be seen from the figure above in Linux.

Detailed explanation of Linux process priority adjustment method Detailed explanation of Linux process priority adjustment method Mar 15, 2024 am 08:39 AM

Detailed explanation of the Linux process priority adjustment method. In the Linux system, the priority of a process determines its execution order and resource allocation in the system. Reasonably adjusting the priority of the process can improve the performance and efficiency of the system. This article will introduce in detail how to adjust the priority of the process in Linux and provide specific code examples. 1. Overview of process priority In the Linux system, each process has a priority associated with it. The priority range is generally -20 to 19, where -20 represents the highest priority and 19 represents

How to stop Task Manager process updates and kill tasks more easily in Windows 11 How to stop Task Manager process updates and kill tasks more easily in Windows 11 Aug 20, 2023 am 11:05 AM

How to Pause Task Manager Process Updates in Windows 11 and Windows 10 Press CTRL+Window Key+Delete to open Task Manager. By default, Task Manager will open the Processes window. As you can see here, all the apps are endlessly moving around and it can be hard to point them down when you want to select them. So, press CTRL and hold it, this will pause the task manager. You can still select apps and even scroll down, but you must hold down the CTRL button at all times.

Why do processes in Linux sleep? Why do processes in Linux sleep? Mar 20, 2024 pm 02:09 PM

Why do processes in Linux sleep? In the Linux operating system, a process can become dormant due to a number of different reasons and conditions. When a process is in a dormant state, it means that the process is temporarily suspended and cannot continue execution until certain conditions are met before it can be awakened to continue execution. Next, we will introduce in detail several common situations when a process enters hibernation in Linux, and illustrate them with specific code examples. Waiting for I/O to complete: When a process initiates an I/O operation (such as reading

How to detect if there is no PHP process in Linux system How to detect if there is no PHP process in Linux system Mar 16, 2024 am 11:42 AM

"Detection method of no PHP process in Linux system, specific code examples are required" When using Linux system for web development, we often rely on PHP process to handle dynamic pages and logic, and sometimes we may need to monitor whether there is a PHP process on the server. This article will introduce a method to detect whether there is a PHP process in a Linux system and give specific code examples. Why is it necessary to detect the PHP process? In web development, the PHP process plays a vital role. It is responsible for parsing and executing PHP processes.

See all articles