Skip to content

Tag: c++

Setting GDB hardware watchpoint/how to set software watchpoint

An earlier question explained that on x86 the size of objects being watched is limited by debug registers. As expected, I can “watch” a double variable. But I can’t watch a double datamember, for example, produces But when you try to continue execution, it says Could not insert hardware brea…

How I can get ports associated to the application that opened them?

I need to get a list of all opened ports on my machine and what application opened them. I need to get this information programmatically. Thanks. Answer I was hoping a cleverer answer would appear. I did just this (programmatically in Python), in an attempt to rewrite a program called NetHogs. My version is h…

how to read output of system(‘ls’)?

I am doing some file IO with c code. I have a particular pattern in my file. I can verify this by a shell command cat abc.txt | grep abc | wc -l. When I execute the same command using System(), it give proper output, but I have no clue how can I get its output into a variable and

How to change Keyboard Layout (a X11 API solution)

I want to change keyboard layout in Linux by programming, What X11’s API function does this? Answer I found one good solution. It’s a c++ class wrriten by Jay Bromley, that I can add to my app and using it. source code It’s very easy to use: you can read source code and found some another us…

Linux, timerfd accuracy

I have a system that needs at least 10 mseconds of accuracy for timers. I went for timerfd as it suits me perfectly, but found that even for times up to 15 milliseconds it is not accurate at all, either that or I don’t understand how it works. The times I have measured were up to 21 mseconds on a

Uptime under linux in C

How can I retrieve uptime under linux using C? (without using popen and/or /proc) Thanks Answer Via top or via uptime, but I don’t know about any syscall, someone will for sure 🙂 uptime should be rather easy to parse. Just stumbled into this:

Why does setupterm terminate the program?

This is sample program from “Beginning Linux Programming” book: #include <stdio.h> #include <term.h> #include <curses.h> #include <stdlib.h> int main() { setupterm(“unlisted”, fileno(stdout), (int *)0); printf(“Done.n”); exit(0); } Running it, I have…