Add fork handlers, based on pthread_atfork