In Linux, the strace
command is similar to the truss
command in Unix, and is used to monitor and diagnose system calls made by a process. It can be used to trace the execution of a program, including the system calls it makes and the signals it receives.
To use the strace
command, simply type strace
followed by the name of the program you want to trace:
strace program
This will display a trace of the system calls made by the program
as it executes. For example:
execve("/usr/bin/program", ["program"], 0x7fffdc8d6e30 /* 62 vars */) = 0 brk(NULL) = 0x555555554000 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=118495, ...}) = 0 mmap(NULL, 118495, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f57b2c37000 close(3) = 0 ...
You can also use options to customize the output of the strace
command. For example, the -c
option can be used to summarize the system call statistics, and the -f
option can be used to trace child processes created by the program:
strace -c -f program
For more options and usage examples, you can refer to the strace
man page by typing man strace
at the command prompt.