Exit Callback Functions (The GNU Awk User’s Guide)
From Get docs
Gawk/docs/latest/Exit-Callback-Functions
Next: Extension Version String, Previous: Extension Functions, Up: Registration Functions [Contents][Index]
17.4.5.2 Registering An Exit Callback Function
An exit callback function is a function that gawk calls before it exits. Such functions are useful if you have general “cleanup” tasks that should be performed in your extension (such as closing database connections or other resource deallocations). You can register such a function with gawk using the following function:
void awk_atexit(void (*funcp)(void *data, int exit_status),
void *arg0);
- The parameters are:
funcp- A pointer to the function to be called before
gawkexits. Thedataparameter will be the original value ofarg0. Theexit_statusparameter is the exit status value thatgawkintends to pass to theexit()system call. arg0- A pointer to private data that
gawksaves in order to pass to the function pointed to byfuncp.
Exit callback functions are called in last-in, first-out (LIFO) order—that is, in the reverse order in which they are registered with gawk.