Describe the bug
Shell scripts which create background processes leave 'zombie' (defunct) processes behind when the script is terminated with an interrupt (ctrl-c). The processes are owned by the root process (1) and are already dead; they can't be killed or removed (hence, zombie). These accumulate over time, and the kernel does not 'harvest' or remove them. We can find no way to prevent this. No matter how we start the process (using &, concurrently, npm run all, etc.) the zombies remain when the script is stopped. Trying to catch the signal in the script does not help.
Steps to reproduce
This simple script will cause zombie processes to be left behind. Doing this inside package.json won't help, nor will trying to catch the signals in the script itself.
# Usage: ./dev.sh
# Generate the routes and watch for changes
routify run --dynamic-imports &
sleep 2
# Pack the JavaScript and watch for changes
rollup -c -w &
sleep 3
# Start the web server and watch for changes
sirv public --no-clear --single --dev
My processes include:
UID PID PPID C STIME TTY TIME CMD
gitpod 1 0 1 00:45 ? 00:00:00 /theia/supervisor run
gitpod 14 1 19 00:45 ? 00:00:07 /theia/node/bin/gitpod-node ./src-gen/backend/main.js /workspace/costvine-client-svelte --port 23000 --host
gitpod 1082 14 0 00:45 pts/0 00:00:00 /bin/bash -i
gitpod 1103 14 4 00:45 ? 00:00:01 /theia/node/bin/gitpod-node /theia/node_modules/@theia/core/lib/node/messaging/ipc-bootstrap.js
gitpod 1247 14 2 00:45 ? 00:00:00 /theia/node/bin/gitpod-node /theia/node_modules/@theia/json/lib/node/json-starter --stdio
gitpod 1661 1 0 00:45 ? 00:00:00 [node] <defunct>
gitpod 1695 1 0 00:45 pts/0 00:00:00 [sh] <defunct>
gitpod 1736 1 1 00:45 pts/0 00:00:00 [node] <defunct>
gitpod 1760 1 31 00:45 pts/0 00:00:07 [node] <defunct>
gitpod 1907 14 8 00:45 ? 00:00:01 /theia/node/bin/gitpod-node /theia/node_modules/@theia/plugin-ext/lib/hosted/node/plugin-host.js
gitpod 1962 1907 22 00:45 ? 00:00:01 /home/gitpod/.sdkman/candidates/java/current/bin/java -noverify -Xmx64M -XX:+UseG1GC -XX:+UseStringDeduplic
gitpod 2099 1082 0 00:45 pts/0 00:00:00 ps -aef
Expected behavior
We expect the kernel to harvest the zombies. There are ways to accomplish this.
Additional information
https://blog.phusion.nl/2015/01/20/docker-and-the-pid-1-zombie-reaping-problem/
https://github.com/krallin/tini
Describe the bug
Shell scripts which create background processes leave 'zombie' (defunct) processes behind when the script is terminated with an interrupt (ctrl-c). The processes are owned by the root process (1) and are already dead; they can't be killed or removed (hence, zombie). These accumulate over time, and the kernel does not 'harvest' or remove them. We can find no way to prevent this. No matter how we start the process (using &, concurrently, npm run all, etc.) the zombies remain when the script is stopped. Trying to catch the signal in the script does not help.
Steps to reproduce
This simple script will cause zombie processes to be left behind. Doing this inside package.json won't help, nor will trying to catch the signals in the script itself.
My processes include:
Expected behavior
We expect the kernel to harvest the zombies. There are ways to accomplish this.
Additional information
https://blog.phusion.nl/2015/01/20/docker-and-the-pid-1-zombie-reaping-problem/
https://github.com/krallin/tini