Within the child process, is there any way that it determine whether it was launched as a fork with overlay memory, or a vfork with shared memory? Basically, our logging engine needs to be much more careful (and not log some classes of activity) in vfork. In fork it needs to cooperate with the parent process in ways that it
Tag: c++
xcb_poll_for_event causes 100% usage of one cpu core
I’m learning c and messing around with xcb lib (instead of X11) on a raspberry pi4. The problem is that when implementing the events loop with xcb_poll_for_event instead of xcb_wait_for_event, one core of four is 100% full. What am I doing wrong? And is there any benefit of using wait_for_event (blocking way) instead of xcb_poll_for_event(non blocking)? The goal is to
Should I release data after the use of get_user_pages_fast?
I’m using the get_user_pages_fast, which I allocate a memory buffer in the user and create a pages in the kernel space. Should I free the struct pages** after the use this memory? or call to specific release function? Thanks! Answer From documentation on get_user_pages() (which has similar functionality, but with more parameters, and needs a semaphore held): Each page returned
How to use system() in a kernel module as stdlib.h cannot be used in a kernel program?
When developing a kernel module in Linux, using the C standard library isn’t allowed. However, in case I need to use some common functionality like system(), how do I implement this? Answer The answer is: you don’t. There are very, very few instances in which you would need to do something similar to system(), that is to call a user-space
“add-symbol-file” can’t recognize .bss & .data symbols when using kgdb to debug kernel modules
I am trying to use gdb 8.3.1 for the kernel module on RPI-4 board. When I use the command add-symbol-file to add .bss and .data sections, it doesn’t work. The Kernel version is 5.4 and CONFIG_DEBUG_INFO is turned on. I list the simple code, dmesg and kgdb info below. If you have any idea, please give me some advice. Module
Get files access permissions using stat() in C
I just started learning linux/C, i just want to show the names of all the files of the directories given in argument, and their access permissions by using stat() which causes some problems. It actually shows the correct name/mode of all the files included in the current directory, but for the other directories given in argument, it does give the
Send a kill signal to self
I have a C++ code that runs a linux command, I want to simulate segfault i.e. SIGSEGV while executing that linux command from by C++ code. So my code looks like this What should I put in “cmd” so that it can send SIGSEGV to the sub-process created by calling this function? Answer Sending kill signal to self can by
How do I print array of u16 in C?
I’d like to print both MSB and LSB of a u16 variable, here is my code: This code just print the LSB part in hexa format, but can you tell me how do I print the MSB part? Answer This code just print the LSB part Well of course, buf[0] = reg; only copies 8 bits. And what result you
Problem with same thread ID for different threads
I am having trouble with my threads. I am trying to create 10 threads and for each thread I want to print the thread ID. I am able to print the thread ID but the problem is that all threads prints out the same thread ID. This is my code: main: mqClient: When testing two threads this is the output
Unexpected behaviour of SO_SNDTIMEO and SO_RCVTIMEO
I’m trying to set the timeout for the blocking TCP socket on Linux using setsockopt with SO_SNDTIMEO and SO_RCVTIMEO. But for some reason I get a lock while waiting on recv call. Consider the minimal example. I’ve shortened it a bit for readability, the full code is available in this gist. I create a server socket and set the timeouts