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…
Tag: c++
Why can only async-signal-safe functions be called from signal handlers safely?
I am still a little confused as to why exactly it is unsafe to receive a signal and call a non async safe function from within that signal handler. Could someone explain the reasoning behind this and possibly try and give me some references that I can follow to read up more on this myself? In other words I am
How to invoke scull_open() in user-space, where scull_open is defined in scull kernel driver
I am newbie to Linux device driver programming. I am just trying to use the scull driver which is explained in Linux Device Drivers. Would like to invoke the scull_open() from user-space for write/read or close operations. Currently I’m able to insert the scull module successfully using insmod and got t…
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 …
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 …
Implement a similar module_init as Linux kernel, but meet some trouble in ld script
I like the linux kernel module_init function very much, I would like to implement the same function for my user space applications. I try to modify the linker script to do this: 1, copy a x86-64 standard ld script 2, add my customized section 3, put the init function pointer into moudle_init section 4, compil…
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 c…
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 …
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…