I learned from this link Why is address 0x400000 chosen as a start of text segment in x86_64 ABI? that 64-bit Linux process start address by default should be 0x400000, but on my Ubuntu, I only found my bash process starts from a very high base address (0x55971cea6000). Any one knows why? and how does dynamic…
Tag: c++
using file lock for a single instance program fails if spawn child process
I need to have a single instance program in Linux. That is if someone tries to run the program the new instance should print a message and exit. At the moment I have a lock mechanism like this: The problem is if I do anything that spawns child processes using int system(const char *command); and at some point…
How to format unix time (sec+usec+nsec) string?
I have this function which works just fine. It gives me current system time the way I need: Now I need to also be able to print timestamps I receive from 3rd party lib in 2-3 variables – sec, usec, nsec (optional). Can I somehow construct timespec from these values and reuse the code I already have? Ans…
Should mqueues be protected by semaphores
Should read mq_receive and write mq_send be protected by semaphores when accessing a queue in a multiprocess program or is there any sort of protection alredy built in Answer It’s always recomended to read the formal documentation for API you are using. Specifcally for mq_receive and mq_send these are: …
icpc error in compiling over-aligned dynamic allocated variables
I am trying to compile a code in C++, that uses over-aligned variables. If I try to compile the following code (a MWE) everything runs smoothly if I use icpx or g++ (in all the cases, the flag -std=c++17 is given to the compiler). However, when compiling using Intel icpc, I got the following error and I do no…
Execute cat command to overwrite file
I am trying to execute the cat command from my C# code, but I am running into problems. So, this is just a very simple test, but I end up with the error: Error: cat: ‘>’: No such file or directory Now… both source and target files actually exist.. and same result if target file does not e…
Can’t redirect printf to pipe
I want to redirect the output of printf to a pipe, but for some reason it doesn’t seem to work. What does work is using write instead. This is my program if I replace write with the commented line, my program just blocks Answer Either add a new line character (n) to your output or use fflush() as Barmar…
why does the local array has extra empty location at the end(c/c++/gcc)?
Check below program, In the above program, even though array size is 10, after the first array there is exactly 6 extra locations reserved in the stack (12bytes), I am wondering why this extra space got reserved? and this extra space size is varying for different size(Its not 12 for size 20). Can anybody expl…
Fast byte copy C++11
I need to convert C# app which uses extensively bytes manipulation. An example: Basically BitConverter and Buffer.BlockCopy called 100s times per sec. There are several classes that inherit from the base class above doing more specific tasks. For example: What approach in C++ should I look into? Answer Best o…
About memory allocation, does C malloc/calloc depends on Linux mmap/malloc or the opposite?
As far as I know, C has the following functions, e.g: malloc, calloc, realloc, to allocate memory. And the linux kernel also has the following functions, e.g: malloc, mmap, kmalloc, vmalloc… to allocate memory. I want to know which is the lowest function. If you say, “Linux kernel is the lowest fu…