I am working on an assignment where I am implementing the unix history command in a shell. In my program I have written a signal handler for SIGINT. When a user enters (ctrl)(c) their history is displayed.
When my program terminates I need to store the history in a file. Is there an easy way to detect when my program has exited? Or do I need to have a signal handler for every type of signal ((ctrl)(d), pausebreak, etc).
atexit()is probably what you’re looking for, see the manual page: man 3 atexitUsage is something like:
Another option is to use the
destructorattribute (GCC/Clang):