Menu

Reference / Process

workers()

function
function workers(int $n): int

Fork into $n workers and return this worker's index.

The original process is worker 0 and the forks are 1 to $n - 1. The workers are unsupervised: one that dies stays dead; use {@see supervise} to restart crashed workers. If a fork fails, the program continues with fewer workers.

Parameters

$n int
number of workers, including the original process

Returns

int — this process's worker index

View source