Home Backend Development PHP Problem How php manages processes

How php manages processes

Sep 20, 2019 pm 01:15 PM
php

How php manages processes

Process Management-Preventing Processes from Becoming Zombie Processes

After the process is created, how do you manage the child processes?

Using signals to manage child processes, there are generally two situations: (Recommended learning: PHP programming from entry to proficiency)

posix_kill() : This function does not, as the name suggests, operate the child process by sending a signal to the child process. When necessary, you can choose to send a process termination signal to the child process to terminate the child process;

pcntl_waitpid(): Wait for or return the child process status of fork. If the specified child process has exited when this function is called (commonly known as a zombie process), this function will return immediately and release all system resources of the child process. This The process can prevent the child process from becoming a zombie process, causing a waste of system resources;

Orphan process: The parent process hangs up, and the child process is taken over by the init process with pid=1 (wait/waitpid) , until the child process's own life cycle ends and the system reclaims resources and the parent process takes relevant recycling operations

Zombie process:The child process exits, and the parent process does not obtain the child process through wait/waitpid Status, process number occupied by the child process and other resource descriptors still exist, causing harm: for example, the process number is limited, and the process number cannot be released, resulting in that there may be no process number available in the future

**Used in the parent process: pcntl_wait Or the purpose of pcntl_waitpid is to prevent the worker from becoming a zombie process

Function: After using pcntl_wait(), after the child process dies, the parent process will also be stopped**

Finally we pass the picture below Let’s briefly summarize and describe the process of multi-process implementation:

How php manages processes

Process Management-Inter-process Communication

Queue: such as Redis , Recommended

socket: Recommended

Pipeline: The implementation is complex, and the pipe (pipe) exists in the form of a file, and there is a hard disk IO performance bottleneck

Signal: The amount of information carried is small , difficult to manage

Process management-switch to daemon process

Use & implement

php deadloop.php &

The above is the detailed content of How php manages processes. 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 Article

Hot Article

Hot Article Tags

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)

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles