How do I make sure that a socket bound to a port is properly released on process exit such that the port can be reused without bind() failing with EADDRINUSE? I
TCP/IP stack keeps port busy for sometime even after close() - socket will stay in TIME_WAIT and TIME_WAIT2 state.
If I'm not mistaken, usually it takes 2 minutes so if you need to use the same port immediately set SO_REUSEADDR option on your socket before binding, just like Ivo Bosticky suggested.