fatal error: cannot open file – does awk flush output when interrupted by SIGINT?
0 reputation · 23 Jan 2023, 21:52 UTC
Goal
Investigate whether GNU Awk flushes partially written data to stdout or output files when it receives a cancellation signal such as SIGINT. The documented error string "fatal error: cannot open file" is used as a reliable anchor for parsing error logs, but it does not describe signal handling behavior.
Constraints and Uncertainty
Awk has no built‑in timeout mechanism; external utilities like timeout or shell traps are required to stop long‑running scripts. POSIX does not specify how awk should behave on signal delivery, and implementations differ: some terminate immediately without flushing, while others may ignore the signal unless explicitly handled. The lack of a documented graceful‑shutdown API leaves data integrity uncertain in pipelines that rely on complete output.
Unresolved Questions
- When awk is terminated by
SIGINT, does it automatically flush any data remaining in its output buffers tostdoutor open files? - If not, what mechanisms (e.g., external traps, custom BEGIN/END blocks) can reliably guarantee that all processed records are written before termination?
- Is there any configuration or signal‑handling extension available in recent GNU Awk releases that allows a graceful shutdown on cancellation?