Skip to content

Concatenating Files And Insert New Line In Between Files

I have multiple files which I want to concat with cat. Let’s say I want to concat so that the final file looks like: Instead of this with usual cat File*.txt > finalfile.txt What’s the right way to do it? Answer You can do: Make sure the file finalfile.txt does not exist before you run the abov…

Is malloc deterministic?

Is malloc deterministic? Say If I have a forked process, that is, a replica of another process, and at some point both of them call the malloc function. Would the address allocated be the same in both processes? Assuming that other parts of execution are also deterministic. Note: Here, I’m only talking …

Why makecontext does not work with pthreads

From makecontext() manual… Due to limitations in the current pthread implementation, makecontext should not be used in programs which link against the pthread(3) library (whether threads are used or not). Now my question is, why it doesn’t work and what are the alternative methods. Actually I&#821…

Turn on core/crash dumps programmatically

I know I can run “ulimit -c unlimited” In the shell to turn on core dumps for the current user. What I am wondering is how can I do this programmatically from C? I see there is a ulimit call, but it’s been deprecated in favour of get/setrlimit. What I want to know is what is the equivalent c…

undefined reference to sync_fetch_and_add_4

Whenever I try to use __sync_fetch_and_add with -m32 on a 64 bit machine, I get the following error, while it compiles fine with normal 64 bit. I am using gcc compiler 4.1.2. What can be the problem here and what is the solution? Answer Using -march=i486 flag did the trick for me.