Skip to content
Advertisement

Tag: c++

thread level memory consumption of process

How do I get per thread based memory consumption of a process in Linux? I understand that we can use /proc/pid/task/tid/statm, but thats not helping my case. All the threads show same value and its same as PID’s statm. We can do valgrind but I am not looking for any invalid read/write or leaks. Valgrind will not tell me any

How to eject the CD Drive on Linux using C?

I was reading through this Advanced Linux Programming tutorial when I encountered a problem. I was trying to eject the CD-ROM drive using this code: Then I try to compile this code and get the following output: So what am I doing wrong? Answer The error message you’re seeing looks like something is wrong in your #include lines, not with

How do I find the size of mounted USB flash drive in C?

I have a flash drive device (/dev/sda1) mounted to /mnt on an embedded linux system (kernel 2.6.23). Using C how do I work out the size of the drive? Answer On Linux, if you’re not worried about portability (C doesn’t know about drives, so any such specific code will be unportable), use statfs():

struct ip_mreq disappears when compiling with -std=c99

On some of our linux boxes compiling with gcc -std=c99 makes struct ip_mreq disappear (included from netinet/in.h) Is there some other interface we are supposed to use ? Answer Try –std=gnu99. The default for GCC is ‘–std=gnu89’ which means C89 with GNU extensions. By selecting ‘–std=c99’ you are enabling C99, but disabling the GNU extensions. ‘–std=gnu99’ will select both C99

fcntl, lockf, which is better to use for file locking?

Looking for information regarding the advantages and disadvantages of both fcntl and lockf for file locking. For example which is better to use for portability? I am currently coding a linux daemon and wondering which is better suited to use for enforcing mutual exclusion. Answer What is the difference between lockf and fcntl: On many systems, the lockf() library routine

Dynamic Shared Library compilation with g++

I’m trying to compile the following simple DL library example code from Program-Library-HOWTO with g++. This is just an example so I can learn how to use and write shared libraries. The real code for the library I’m developing will be written in C++. If I compile the program with gcc it works fine. When I change the filename and

What is time_t ultimately a typedef to?

I searched my Linux box and saw this typedef: But I could not find the __time_t definition. Answer The time_t Wikipedia article article sheds some light on this. The bottom line is that the type of time_t is not guaranteed in the C specification. The time_t datatype is a data type in the ISO C library defined for storing system

C non-blocking keyboard input

I’m trying to write a program in C (on Linux) that loops until the user presses a key, but shouldn’t require a keypress to continue each loop. Is there a simple way to do this? I figure I could possibly do it with select() but that seems like a lot of work. Alternatively, is there a way to catch a

GCC and ld can’t find exported symbols…but they’re there

I have a C++ library and a C++ application trying to use functions and classes exported from the library. The library builds fine and the application compiles but fails to link. The errors I get follow this form: app-source-file.cpp:(.text+0x2fdb): undefined reference to `lib-namespace::GetStatusStr(int)’ Classes in the library seem to be resolved just fine by the linker, but free functions and

Advertisement