Skip to content

Bug: execve on Windows changes pid #1334

@andrei-markeev

Description

@andrei-markeev

Contact Details

No response

What happened?

On linux, the PID doesn't change inside a forked process if you call execve. So you can fork, take the PID and send signals to the process. This is what I am trying to achieve.

It seems the PID does change on Windows though. If I try to send a signal to a spawned process, I get error "kill() failed: No such process (win32 error 87)". If I inspect the processes, a process with such PID is indeed not found, and the spawned process has a different PID.

If I add a Sleep, the process with forked PID exists during the sleep, but when the calc process is spawned, the forked process is killed and calc has a completely different PID and doesn't appear "under" redbean i.e. shutting down redbean process group doesn't kill it.

I wonder is there a way to simulate Linux behavior in Windows? If not, maybe there at least a way to get the spawned PID somehow? Also, if it is not possible to achieve on Windows, I think it should at least be documented.

Version

redbean 3.0.0

What operating system are you seeing the problem on?

Windows

Relevant log output

$ ./redbean-3.0.0.com 
I2024-12-06T12:50:53.864718:tool/net/redbean.c:7052:redbean-3:13316] (srvr) listen http://192.168.56.1:8080
I2024-12-06T12:50:53+001019:tool/net/redbean.c:7052:redbean-3:13316] (srvr) listen http://192.168.99.1:8080
I2024-12-06T12:50:53+001114:tool/net/redbean.c:7052:redbean-3:13316] (srvr) listen http://192.168.1.225:8080
I2024-12-06T12:50:53+001122:tool/net/redbean.c:7052:redbean-3:13316] (srvr) listen http://127.0.0.1:8080
I2024-12-06T12:50:53+000738:tool/net/redbean.c:7052:redbean-3:13316] (srvr) listen http://172.22.224.1:8080
>: pid = unix.fork(); print(pid); if pid == 0 then unix.execve('/C/WINDOWS/system32/calc.exe', {'/C/WINDOWS/system32/calc.exe'}) end
28540
>: 0
>: pid
28540
>: unix.kill(pid, unix.SIGINT)
nil     "kill() failed: No such process (win32 error 87)"
>:
I2024-12-06T12:51:43.839580:tool/net/redbean.c:7077:redbean-3:13316] (srvr) received SIGHUP
I2024-12-06T12:51:43+002503:tool/net/redbean.c:7081:redbean-3:13316] (srvr) killing process group
I2024-12-06T12:51:43+002872:tool/net/redbean.c:7085:redbean-3:13316] (srvr) shutdown complete

Metadata

Metadata

Assignees

Labels

acceptedWe intend to address this issue.libcmedium severityUsed to report medium severity bugs (e.g. Malfunctioning Features but still useable)

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions