The make command hangs up when it is run as init (PID=1) and its child processes are terminated with SIGINT
$ ls
loop.sh Makefile run-loop.sh
$ cat loop.sh
#!/bin/bash
trap 'echo SIGTERM && exit 0' SIGTERM
trap 'echo SIGINT && exit 0' SIGINT
while true; do :; done
$ cat run-loop.sh
#!/bin/bash
trap 'kill $pid; exit 0' SIGINT
./loop.sh &
pid=$!
wait $pid
$ cat Makefile
all:
/root/run-loop.sh
.PHONY: all
$ docker run -it --rm --name test -v $(pwd):/root -w /root rust /root/loop.sh
^CSIGINT
$ docker run -it --rm --name test -v $(pwd):/root -w /root rust /root/run-loop.sh
^CSIGTERM
$ docker run -it --rm --name test -v $(pwd):/root -w /root rust make
/root/run-loop.sh
^CSIGTERM
(The make command hangs up here (*). Run ``docker kill test'' from another terminal...)
$
Running docker exec ps at (*)
gives the following result.
$ docker exec -it test ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 96 06:59 pts/0 00:00:28 make
root 8 0 0 07:00 pts/1 00:00:00 ps -ef
Note however that either calling loop.sh directly from Makefile or running loop.sh in foreground does not hang.
$ sed -i -e s/run-loop/loop/ Makefile
$ cat Makefile
all:
/root/loop.sh
.PHONY: all
$ docker run -it --rm --name test -v $(pwd):/root -w /root rust make
/root/loop.sh
^CSIGINT
make: *** wait: No child processes. Stop.
$ cat > run-loop.sh
#!/bin/bash
./loop.sh
$ sed -i -e s/loop/run-loop/ Makefile
$ cat Makefile
all:
/root/run-loop.sh
.PHONY: all
$ docker run -it --rm --name test -v $(pwd):/root -w /root rust make
/root/run-loop.sh
^CSIGINT
make: *** wait: No child processes. Stop.
$