To clarify, close(s) causes a process to drop its reference to a socket. shutdown(s,2) will terminate the socket regardless of what other processes reference it. So as long as one process (in this case the parent) still calls mysql_close(), the entire connection state will be cleaned up at that time.