Skip to content
Advertisement

Tag: c++

Why are strings statically allocated in C?

In C (at least) local string variables are allocated in the .rodata section or .data segment generally. Why not store them on the stack, since it is a local variable? Will the string data be in memory for the full execution time? Is that not a waste of memory? Answer How have you drawn the conclusion that string is statically

Futex and pthreads issue

I’m testing futexes with pthreads. I’ve written following program: And sometimes it returns 0 as a sum which is proper value but sometimes the returned value of sum is different than 0. My question is why the returned values of “sum” are different than 0? I suspect that there is something wrong with locking but for the moment I cannot

trying to cause SIGSEGV in mmap

I’m trying to create a memory mapping of length greater than the underlying file. When I access pages of the mapping (which are not correspondingly mapped to a file), a SIGBUS is caused. However when I try to access the memory outside the memory mapping length, it should cause SIGSEGV (but isn’t), why is that? Answer Stopping your program and

What is the true getrusage resolution?

I’m trying to measure getrusage resolution via simple program: And when I run it, I usually get output similar to the following: ema@scv:~/tmp/getrusage$ ./gt u:0.000562 uz:0.000563 cnt:1 ema@scv:~/tmp/getrusage$ ./gt u:0.000553 uz:0.000554 cnt:1 ema@scv:~/tmp/getrusage$ ./gt u:0.000496 uz:0.000497 cnt:1 ema@scv:~/tmp/getrusage$ ./gt u:0.000475 uz:0.000476 cnt:1 Which seems to hint that the resolution of getrusage is around 1 microsecond. I thought it should be

Writing a small file blocks for 20 ms

I discovered that on my Ubuntu 22 server, attempting to write to a file, often induces around 20ms delay, even when only writing a few bytes. Here is some basic code that demonstrates the problem: And here is the output: It seems more likely to happen if there is a bit of delay between attempts, and also more likely to

Writing into a device file prints “Invalid argument”

I am currently working on a device driver where I want to write a sentence to that driver and display it in the kernel. Reading an internal buffer and calling the driver with cat works perfectly fine. However, if I try to write to the device driver it returns the following message: I have the following code for my device

Advertisement