How php manages processes
Sep 20, 2019 pm 01:15 PMProcess 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:
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!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

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