I have a strange situation.
I have a c-written program “A” which takes as argument the name of other executables, e.g. “B”, “C”, “D” etc.. The main job of “A” is to fork and start “B”, “C” etc, then check if they crash, and in that case restart the crashed process.
Also, process “A” runs a separated thread for RTC sync purposes.
“A” is started as /bin/sh -c A B C D etc
.
I am on an embedded environment and I am using a customized kernel derived from Linux 4.4.57.
Now to the the problem: it happens sometimes my process “A” becomes zombie!
Some observations I made:
- the parent process
/bin/sh -c
, which started “A” is still alive; - none of the child processes “B”, “C”, etc. are dead;
- “A” responds to signals;
- if I kill the parent process
/bin/sh -c
, “A”'s parent becomes init (1) but still, the process remains zombie; - the only way to kill the zombie “A” is to issue a
kill -9 «pid-of-A»
; - the RTC sync thread is still running!;
Now, because of “A” responding to signals and the internal thread still running, this zombie process is driving me crazy.
What explains such behavior? Might it be something related to kernel build configuration?
EDIT: I have looked better at the code and found out that “A” is started as a daemon with the following command:
start-stop-daemon -b --start --quiet --pidfile /var/run/A.pid --background --exec /bin/sh -- -c "A B C D > /var/log/log 2>&1"
UPDATE: I've been able to replicate the same exact behavior by calling pthread_exit(). The problem is that I can't find any reference to phread_exit on the original source. Is there any other way the main thread might stop leaving alive all the others?