Skip to content
Advertisement

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 mishandles the case where the first byte

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 you want to measure total elapsed

C segmentation fault on linux with strncmp

This works (‘Y’ must be single quotes): This gives segmentation fault: strncmp must be going off the deep end but not sure why since I’m passing a casted toupper() as (char *). Without the casting, same error. FYI user_input() is (N.B. vars are global): Thank you. Answer The return value of toupper is another character, not a pointer to a

Does the qstr struct in a kernel dentry hold the filename of a Linux file?

Below is a snippet of the Linux dentry struct from http://lxr.free-electrons.com/source/include/linux/dcache.h#L150. The struct contains a member struct qstr d_name – definition below. I would like to know if this is the name of the particular file that would correspond to this dentry at runtime. What confuses me is that proc/PID/maps uses struct dentry_operations -> d_name (another member of dentry) to

What are these unfamiliar lines in the C preprocessed file?

This is an output of the GNU cpp on a Hello World program in C. I am wondering what do these lines mean? # Number Header_File_Location [Numbers] Are these some kind of dependencies? If yes, then on what? Line numbers? Answer Those are line number directives, and tells the compiler what line and file the next part of the source

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 detect that child process has exited I would like to determine the reason

Advertisement