I wrote a Linux program that creates some persistent TCP connections, and I would like my program to close() those TCP sockets just before the Linux-computer goes to sleep, so that the remote peer isn't left with a non-responsive "zombie" TCP connection.
According to this answer, one way to do that is to modify the /etc/pm/sleep.d file to run a special notification app, but I'd prefer not to do it that way since modifying system config files is risky (and in many cases not possible if my program does not have permissions to do so).
Windows and MacOS/X have C-based notification APIs for this sort of thing; is there anything similar in Linux-land?