Strace - System call tracer
Observe the backstage actions of a program as it runs, without the need to recompile.
Strace is one of the key debugging tools discussed in the book "Self-Service Linux" [1] written by Mark Wilding and Dan Behman.
With Strace you can run a program and see all the system API calls ("syscalls") like "read" and "write". You can see immediately when the program attempted to read a file and could not find it, or tried to write to a file and did not have enough permissions to succeed.
Alternatives to Strace are: debugging the code with a debugger like GDB or enabling verbose output of the program. If you need Strace, you probably already enabled all the debug verbosity of the investigated program, and have not found the cause of the problem.
Debugging with GDB requires more expertise than running the program with Strace and analyzing the output, which can be done effectively by any programmer.
To try Strace in action, run: strace cat /dev/null
and observe the output. You will see the moment when the "cat" command opens the /dev/null
path for reading:
openat(AT_FDCWD, "/dev/null", O_RDONLY) = 3
The book "Self-Service Linux" by Mark Wilding and Dan Behman can be obtained on Amazon, or via an O'Reilly subscription [1:1].