Fix signal handler
The function “exit” does not belong to the list of async-signal-safe functions. I guess that a different program design will be needed for your function “printstats”.
What do you suggest? Use _exit() instead?
Use
_exit()instead?
This could be one possibility.
Would you like to consider other software design options?
send patches
I would prefer to clarify acceptable software design directions before contributing patches in a source code format.
I'm not familiar with your proposed alternatives, please illustrate them in form of patches, etc...
The proposed alternatives are already illustrated by other information sources. Would you like to become more familiar with the choices?