Home  >  Article  >  Backend Development  >  How php manages processes

How php manages processes

(*-*)浩
(*-*)浩Original
2019-09-20 13:15:053069browse

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:
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
Previous article:How php manages memoryNext article:How php manages memory