How php manages processes

(*-*)浩
Release: 2023-02-24 14:28:01
Original
3035 people have browsed it

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!

Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!