Process Control pcntl_fork
(PHP 4 >= 4.1.0, PHP 5, PHP 7, PHP 8)
pcntl_fork — 현재 실행 중인 프로세스를 분기합니다.
설명
pcntl_fork(): int
pcntl_fork() 함수는 PID와 PPID에서만 부모 프로세스와 다른 자식 프로세스를 생성합니다. 시스템에서 포크가 작동하는 방식에 대한 자세한 내용은 시스템의 fork(2) 매뉴얼 페이지를 참조하십시오.
매개변수
이 함수에는 매개변수가 없습니다.
반환 값
성공하면 자식 프로세스의 PID가 부모의 실행 스레드에서 반환되고 자식의 실행 스레드에서 0이 반환됩니다. 실패하면 부모 컨텍스트에서 -1이 반환되고 자식 프로세스가 생성되지 않으며 PHP 오류가 발생합니다.
Examples
예제 #1 pcntl_fork() 예제
<?php
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork');
} else if ($pid) {
// we are the parent
pcntl_wait($status); //Protect against Zombie children
} else {
// we are the child
}
?>
기타
- pcntl_rfork() - Manipulates process resources
- pcntl_waitpid() - Waits on or returns the status of a forked child
- pcntl_signal() - Installs a signal handler
- cli_set_process_title() - Sets the process title