Closed v-instrumentix closed 1 week ago
mold spawns a child process to do actual linking to hide the latency of process exit. That is, even exit() takes a few hundred milliseconds for processes with large memory image like the linker, and we hide it by spawning a child process.
Zombie processes are processes that have already terminated, but their parents haven't checked their exit statuses using waitpid
.
Usually, when a parent process terminates before its children, the children are adopted by process number 1 (usually /sbin/init), and init calls waitpid
(or possibly wait
) to reclaim process table slots occupied by these orphaned processes.
bash
does that too when it is invoked as pid 1. However, su
doesn't do that.
That's why zombie processes remain in your docker environment. This issue is not limited to mold; it is generally assumed in Unix that orphan processes are reclaimed by pid 1, so other program may also leave zombies in your environment.
There are two "solutions" to the problem:
docker run -it --rm t bash
instead of docker run -it --rm t su -
.Thank you for your exemplary beautiful answer.
Please use Dockerfile as pasted below (also available here). This Dockerfile installs
gcc
,cmake
,make
andmold
, defines trivialCMake
project that usesmold
as linker and provides shell script wrappingcmake
+cmake --build
followed by check formold
processes left.Steps to replicate are as follows (assuming Dockerfile in current directory):
docker build -tt . ; docker run -it --rm t su -
bash /x/b
After each run new zombie processld.mold
will appear (sample output also pasted below).Tested with GCC 11, 12, 13 either with Ninja or Make.
Dockerfile for building MRE: