Using GDB to Dump Program State
Sometimes when a program is running for you want to dump the complete state of all the calls stacks of all threads in a program. This is not so easy to do yourself, but thankfully there are tools like GDB,…
Finding the state of TCP/IP Sockets on Linux
It is not possible through the sockets API to find the connection state of a socket. But on Linux there is a way, a user space way, to find the connection state of a socket. Network information in the Proc…
Setting up Docker for Remote Deployment
How to set up docker servers and clients to communicate with each other over the network securely with HTTPS/TLS.
Build GCC with Musl for Raspbian
Musl is a libc replacement designed for embedded systems. It tries to be compatible with POSIX and where possible with glibc, the default c standard library for GCC. Its code is designed to be better for small memory systems. One…
Adding and Removing Routes in the Linux Routing Table
We will go through how to add and remove null routes in c++, though there is a lot more you can do with Linux’ routing tables. For this project I want to use the routing tables like a firewall. I…
Packing Data Files into Compiled Executables
Have you ever wanted to distribute a compiled binary that included data files packed into the executable file? Embedding a Data File Before Compilation You can do this before compilation by encoding the file into a binary representation, and then…
Generating a Cross-Platform Unique Machine Fingerprint
Sometimes you need a program to know if it is running on the same machine. There are a lot of purposes for this, but a common one is if you are writing a licensing module. You want to generate a…
Fixing File Descriptor Leaks in Long-Lived Servers
So you’ve created a socket server that opens sockets over TCP/IP. After running it for a few hours under heavy load the operating system kills your process with the message “Too many open files”. What happened? The problem On most…
Implementing Read/Write Locks Portably
In multi-threaded programs you often find a usage pattern where many more threads need to read a shared resource than write to it, and where reading the resource would be thread-safe without mutexes if it is not being written. (…
Detecting Crashes in Multi-Threaded Programs
Detecting crashes in multi-threaded systems can be difficult. Often the crashes are difficult to reproduce, and when they happen the faulty operation could have happened many calls ago and so the you don’t get a stack trace at the time…