In my Client-Server program, I am creating a class which opens and uses several file descriptors for reading/writing to ports. In the class destructor, I call close( int ) for all of the descriptors.
My problem is if I abruptly end the program by pressing "Ctrl+Z", for example, the destructor is not called. Hence the sockets are not closed, and the ports are still occupied. As a result, I have to close and re-open Putty just so I can use the same ports again.
Is there way to call the destructor, or at least close all the descriptors, whenever I end the program by pressing "Ctrl+Z" or in some other similar manner?