


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:- Set the SIGCHLD signal processing function in the parent process to SIG_IGN (ignore the signal) ;
- 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 processproduces
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.
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 wait
Get 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. wait
Often 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!

Linux maintenance mode can be entered through the GRUB menu. The specific steps are: 1) Select the kernel in the GRUB menu and press 'e' to edit, 2) Add 'single' or '1' at the end of the 'linux' line, 3) Press Ctrl X to start. Maintenance mode provides a secure environment for tasks such as system repair, password reset and system upgrade.

The steps to enter Linux recovery mode are: 1. Restart the system and press the specific key to enter the GRUB menu; 2. Select the option with (recoverymode); 3. Select the operation in the recovery mode menu, such as fsck or root. Recovery mode allows you to start the system in single-user mode, perform file system checks and repairs, edit configuration files, and other operations to help solve system problems.

The core components of Linux include the kernel, file system, shell and common tools. 1. The kernel manages hardware resources and provides basic services. 2. The file system organizes and stores data. 3. Shell is the interface for users to interact with the system. 4. Common tools help complete daily tasks.

The basic structure of Linux includes the kernel, file system, and shell. 1) Kernel management hardware resources and use uname-r to view the version. 2) The EXT4 file system supports large files and logs and is created using mkfs.ext4. 3) Shell provides command line interaction such as Bash, and lists files using ls-l.

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.

Linux maintenance mode is entered by adding init=/bin/bash or single parameters at startup. 1. Enter maintenance mode: Edit the GRUB menu and add startup parameters. 2. Remount the file system to read and write mode: mount-oremount,rw/. 3. Repair the file system: Use the fsck command, such as fsck/dev/sda1. 4. Back up the data and operate with caution to avoid data loss.

This article discusses how to improve Hadoop data processing efficiency on Debian systems. Optimization strategies cover hardware upgrades, operating system parameter adjustments, Hadoop configuration modifications, and the use of efficient algorithms and tools. 1. Hardware resource strengthening ensures that all nodes have consistent hardware configurations, especially paying attention to CPU, memory and network equipment performance. Choosing high-performance hardware components is essential to improve overall processing speed. 2. Operating system tunes file descriptors and network connections: Modify the /etc/security/limits.conf file to increase the upper limit of file descriptors and network connections allowed to be opened at the same time by the system. JVM parameter adjustment: Adjust in hadoop-env.sh file

This guide will guide you to learn how to use Syslog in Debian systems. Syslog is a key service in Linux systems for logging system and application log messages. It helps administrators monitor and analyze system activity to quickly identify and resolve problems. 1. Basic knowledge of Syslog The core functions of Syslog include: centrally collecting and managing log messages; supporting multiple log output formats and target locations (such as files or networks); providing real-time log viewing and filtering functions. 2. Install and configure Syslog (using Rsyslog) The Debian system uses Rsyslog by default. You can install it with the following command: sudoaptupdatesud


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function