We know that
printf is not async signal safe function. And below is my basic understanding:
Let's say we have called
main method, so the content is written to stdio buffer, just before the buffer get flushed to the file, a signal arrives and the signal handler also calls
printf, and the second
printf append it's content to the buffer, now the buffer has content from first call and second call, which is inconsistent, this is not correct, therefore we cannot use non asyc safe functions in signal handlers.
Is my understanding correct?
If my understanding is correct, then how can async safe function solve this problem? Because the safe function still need to deal with buffer, which still might contain precious call's buff data?