protected function registerTickHandlers()
    {
        $self = $this;
        register_tick_function(function () use ($self) {
            if (!$self->prepared) {
                return;
            }

            if ($self->master) {
                while ($pid = pcntl_wait($status, WNOHANG)) {
                    if ($pid === -1) {
                        pcntl_signal_dispatch();
                        break;
                    }

                    if (empty($self->children[$pid])) continue;

                    $self->children[$pid]->emit('finish', $status);
                    $self->children[$pid]->shutdown($status);
                    $self->clear($pid);
                }
            }

            $self->emit('tick');

            if (!is_resource($self->queue) || !msg_stat_queue($self->queue)) {
                return;
            }

            while (msg_receive($self->queue, 1, $null, 1024, $msg, true, MSG_IPC_NOWAIT, $error)) {
                if (!is_array($msg) || empty($msg['to']) || $msg['to'] != $self->pid) {
                    $self->emit('unknown_message', $msg);
                } else {
                    if ($self->master) {
                        if (!empty($self->children[$msg['from']])
                            && ($process = $self->children[$msg['from']])
                        ) {
                            $process->emit('message', $msg['body']);
                        } else {
                            $self->emit('unknown_message', $msg);
                        }
                    } else if ($msg['from'] == $self->ppid) {
                        // Come from parent process
                        $self->process->emit('message', $msg['body']);
                    }
                }
            }
        });
    }