Tracing a program with strace generates a lot of output because of the sheer number of syscalls every program calls during its runtime. This can become overwhelming very quickly, making it hard to analyze the trace and find what you are looking for. Fortunately, strace has several features that...
One of the great strengths of strace as a debugging tool is that it shows you what a program is doing regardless of whether it was compiled with debug info or not. The downside of this is that you only see the program’s syscall. You can use this information to deduce what is happening in …...
There is probably no debugging tool on Linux that is more valuable and versatile than strace. This tool shows us all the calls a program makes to the operating system, including the data it transmits to the operating system via these calls and the return values sent back by the OS. Therefore, it...
When we debug a program with printf() we have to recompile it whenever we add new printf() statements! Right!? Wrong! With gdb we can add printf() statements without recompiling a program and even add them while it is running. Adding Printfs with GDB Let’s say we have the following example program...
Modern UNIX shells like bash (default on Linux) and zsh (default on macOS) keep a history of all the commands you enter. The easiest way to access this history is by pressing the up and down cursor keys to browse through the last commands. But this is only the tip of the iceberg. There are …...
Most programmers prefer to write code over debugging it. Unfortunately, code breaks a lot more often than we would like and it often breaks in situations that are hard to debug. Therefore, an essential skill as a programmer is to know how to debug your code (and that of others). When facing our...
Structures allow us to combine several variables to create a new data type. Some other languages support the same concept but call it “records”. If you come from object-oriented programming you can think about them as classes without methods. Declaration A structure is declared by the keyword...
So you have set up your Raspberry Pi as a home server and everything works as intended. But what if the SD card fails and all the data you stored on your Raspberry Pi is suddenly lost forever? All storage devices containing important data need to be backed up on a regular basis. And this …...
When we declare a variable of type int and we don’t tell the compiler if it is supposed to be signed or unsigned it is signed by default: This is true for all integer number types (short, int, long, long long). But there is one exception: The char type! The char Type is Special According …...
So there is a process running on your machine and you know it has opened one or more ports but you don’t know the port numbers. Let’s find out how to retrieve them! Legacy Network Tools (netstat) Netstat is the good old go-to tool to figure out all about open network connections on a Linux …...