Skip to content

Tag: c++

Detect client is disconnected

I have a simple program that listens to a socket. Everything goes fine except when the connection is lost in while(1) cycle. In this case the program falls into read from socket for many times without result. How can I detect a disconnected client in while(1) cycle? Answer Change: To: Also, your code mishandl…

Time spends in CPU faster than in reality

I am wondering why my entire application runs in less than 8 seconds while the time obtained from clock_gettime is 19.3468 seconds which is more than two times as much as what happens in reality. Where is the problem from? Update: I am not using any OpenMP explicitly. Answer CLOCK_MONOTONIC should be used if …

How to detect that a child process has crashed?

A child process can: Exit normally (by exiting using exit(0),exit(22), exit(23)) — This is obviously specific to my application Exit abnormally (code throws an exception, receives an unhandled signal, core dumps, etc…) I am doing a fork/exec from a parent process and looping on waitpid, when I det…