This code fails:
```d
import std.process;
void main()
{
auto pid = spawnProcess(["ls"]);
while (true) {}
}
```
with
`std.process.ProcessException@std/process.d(1196): Failed to allocate memory (Cannot allocate memory)`
when the ulimit max open files, divided by 8, is equal or larger than the available memory.
This happened when trying to spawn a process inside a docker container:
install rocky linux (rhel) 768M mem + 768M swap
install docker
docker run --rm -it debian:bullseye
apt-get update && apt-get install -y gcc ldc
create d file
ldc2 -run test.d
Problem: it tries to allocate `RLIMIT_NOFILE * pollfd.sizeof` bytes to pass to poll to try which FDs are open to close them to not accidentally inherit them.
However RLIMIT_NOFILE is on this platform = 1073741816
Workaround: Config.inheritFDs will make std.process not try to close them, thus avoiding the malloc, thus avoiding the crash.
There should probably be a check if RLIMIT_NOFILE is very big and in that case probably try to chunk the polling or do a brute force approach or just see how other standard libraries implemented this issue.
Comment #1 by robert.schadek — 2024-12-01T16:41:04Z