Skip to content

PHP segfaults if pcntl is built as shared module #9298

Closed
@hasso

Description

@hasso

Description

The following code:

<?php

declare(strict_types = 1);

function sigalrm()
{
}

while (true) {

    pcntl_signal(SIGALRM, "sigalrm", false);

    $pid = pcntl_fork();
    if ($pid < 0) {
        printf("pcntl_fork() failed\n");
        exit(-1);
    }

    if ($pid == 0) {
        exit(0);
    } else {
        while (true) {
            posix_kill($pid, SIGALRM);
            $wpid = pcntl_wait($st, WNOHANG);
            if ($wpid > 0) {
                break;
            }
        }

        if (pcntl_wifsignaled($st)) {
            $signo = pcntl_wtermsig($st);
            if ($signo != SIGALRM) {
                printf("##### Worker killed by signal %d ####\n", $signo);
                exit(0);
            }
        }

        printf("Worker exited normally\n");
    }

}

Resulted in this output:

##### Worker killed by signal 11 ####

But I expected this output instead:

Worker exited normally
Worker exited normally
Worker exited normally
Worker exited normally
...

The problem only appears if pcntl is built as shared module (--enable-pcntl=shared). There is no problem if pcntl support is built in (--enable-pcntl).

PHP Version

PHP 8.1.9

Operating System

Debian GNU/Linux 11 (bullseye)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions