Tracing system calls with strace
A GNU/Linux computer may have hundreds of tasks running at a time, but it will possess only one Network Interface, one disk drive, one keyboard, and so on. The Linux kernel allocates these limited resources and controls how tasks access them. This prevents two tasks from accidently intermingling data in a disk file, for example.
When you run an application, it uses a combination of User-Space libraries (functions such as printf
and fopen
) and System-Space Libraries (functions such as write
and open
). When your program calls printf
(or a script invokes the echo
command), it invokes a user-space library call to printf
to format the output string; this is followed by a system-space call to the write
function. The system call makes sure only one task can access a resource at a time.
In a perfect world, all computer programs would run with no problems. In an almost perfect world, you'd have the source code, the program would be compiled with debugging support, and...