Search code examples
cprintfforkdeadlock

printf deadlock - some printf messages ignored if printf used in signal handler


Here is a slide from System Programming course I'm currently taking:

<slide goes here>

catch_child is SIGCHLD handler. How does the output correspond to the code? Why are some "Child #x started" messages not printed?


Solution

  • By definition, deadlock is a situation when no progress is made.

    So it is not that some printf messages are not printed/ignored, but that after some particular printf call the program is waiting for something that will never happen and it keeps waiting there forever.

    For more info about what causes such behavior see: Why are malloc() and printf() said as non-reentrant?