strace: a diagnostic, debugging, and instructional userspace utility for Linux
strace – the Linux syscall tracer
strace is a diagnostic, debugging, and instructional userspace utility for Linux. It is used to monitor and tamper with interactions between processes and the Linux kernel, which include system calls, signal deliveries, and changes in process state.
System administrators, diagnosticians, and troubleshooters will find it invaluable for solving problems with programs for which the source is not readily available since they do not need to be recompiled in order to trace them.

The operation of strace is made possible by the kernel feature known as ptrace.
Some of the features
- Attach to an already running process[pastacode lang=”markup” message=”” highlight=”” provider=”manual” manual=”%24%20strace%20-p%2026380%0Astrace%3A%20Process%2026380%20attached%0A…”/]
- Filter by type of syscall[pastacode lang=”markup” manual=”-e%20trace%3D%25desc%20%20%20%20%20Trace%20all%20file%20descriptor%20related%20system%20calls.%0A%20%20%20%20%20%20%20%20%20%25file%20%20%20%20%20Trace%20all%20system%20calls%20which%20take%20a%20file%20name%20as%20an%20argument.%0A%20%20%20%20%20%20%20%20%20%25fstat%20%20%20%20Trace%20fstat%20and%20fstatat%20syscall%20variants.%0A%20%20%20%20%20%20%20%20%20%25fstatfs%20%20Trace%20fstatfs%2C%20fstatfs64%2C%20fstatvfs%2C%20osf_fstatfs%2C%20and%20osf_fstatfs64%20system%20calls.%0A%20%20%20%20%20%20%20%20%20%25ipc%20%20%20%20%20%20Trace%20all%20IPC%20related%20system%20calls.%0A%20%20%20%20%20%20%20%20%20%25lstat%20%20%20%20Trace%20lstat%20syscall%20variants.%0A%20%20%20%20%20%20%20%20%20%25memory%20%20%20Trace%20all%20memory%20mapping%20related%20system%20calls.%0A%20%20%20%20%20%20%20%20%20%25network%20%20Trace%20all%20the%20network%20related%20system%20calls.%0A%20%20%20%20%20%20%20%20%20%25process%20%20Trace%20all%20system%20calls%20which%20involve%20process%20management.%0A%20%20%20%20%20%20%20%20%20%25pure%20%20%20%20%20Trace%20syscalls%20that%20always%20succeed%20and%20have%20no%20arguments.%0A%20%20%20%20%20%20%20%20%20%25signal%20%20%20Trace%20all%20signal%20related%20system%20calls.%0A%20%20%20%20%20%20%20%20%20%25stat%20%20%20%20%20Trace%20stat%20syscall%20variants.%0A%20%20%20%20%20%20%20%20%20%25statfs%20%20%20Trace%20statfs%2C%20statfs64%2C%20statvfs%2C%20osf_statfs%2C%20and%20osf_statfs64%20system%20calls.%0A%20%20%20%20%20%20%20%20%20%25%25stat%20%20%20%20Trace%20syscalls%20used%20for%20requesting%20file%20status.%0A%20%20%20%20%20%20%20%20%20%25%25statfs%20%20Trace%20syscalls%20related%20to%20file%20system%20statistics.” message=”” highlight=”” provider=”manual”/]
- Trace-only system calls accessing the given path[pastacode lang=”markup” message=”” highlight=”” provider=”manual” manual=”%24%20strace%20-P%20%2Fetc%2Fld.so.cache%20ls%20%2Fvar%2Fempty%0Aopen(%22%2Fetc%2Fld.so.cache%22%2C%20O_RDONLY)%20%3D%203%0Afstat(3%2C%20%7Bst_mode%3DS_IFREG%7C0644%2C%20st_size%3D22446%2C%20…%7D)%20%3D%200%0Ammap(NULL%2C%2022446%2C%20PROT_READ%2C%20MAP_PRIVATE%2C%203%2C%200)%20%3D%200x2b7ac2ba9000%0Aclose(3)%20%3D%200%0A%2B%2B%2B%20exited%20with%200%20%2B%2B%2B”/]
- Perform a full hexadecimal and ASCII dump of all the data read from/written to file descriptors[pastacode lang=”markup” message=”” highlight=”” provider=”manual” manual=”%24%20strace%20-ewrite%3D1%20-e%20trace%3Dsendmsg%20.%2Frecvmsg%20%3E%20%2Fdev%2Fnull%0Asendmsg(1%2C%20%7Bmsg_name%3DNULL%2C%20msg_namelen%3D0%2C%20msg_iov%3D%5B%7Biov_base%3D%22012%22%2C%20iov_len%3D3%7D%2C%0A%7Biov_base%3D%2234567%22%2C%20iov_len%3D5%7D%2C%20%7Biov_base%3D%2289abcde%22%2C%20iov_len%3D7%7D%5D%2C%20msg_iovlen%3D3%2C%0Amsg_controllen%3D0%2C%20msg_flags%3D0%7D%2C%200)%20%3D%2015%0A%20*%203%20bytes%20in%20buffer%200%0A%20%7C%2000000%20%2030%2031%2032%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20012%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%0A%20*%205%20bytes%20in%20buffer%201%0A%20%7C%2000000%20%2033%2034%2035%2036%2037%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2034567%20%20%20%20%20%20%20%20%20%20%20%20%7C%0A%20*%207%20bytes%20in%20buffer%202%0A%20%7C%2000000%20%2038%2039%2061%2062%2063%2064%2065%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2089abcde%20%20%20%20%20%20%20%20%20%20%7C%0A%2B%2B%2B%20exited%20with%200%20%2B%2B%2B”/]
- Perform a syscall fault injection[pastacode lang=”markup” message=”” highlight=”” provider=”manual” manual=”%24%20strace%20-e%20trace%3Dopen%20-e%20fault%3Dopen%20cat%0Aopen(%22%2Fetc%2Fld.so.cache%22%2C%20O_RDONLY%7CO_CLOEXEC)%20%3D%20-1%20ENOSYS%20(Function%20not%20implemented)%20(INJECTED)%0Aopen(%22%2Flib%2Fx86_64-linux-gnu%2Ftls%2Fx86_64%2Flibc.so.6%22%2C%20O_RDONLY%7CO_CLOEXEC)%20%3D%20-1%20ENOSYS%20(Function%20not%20implemented)%20(INJECTED)%0Aopen(%22%2Flib%2Fx86_64-linux-gnu%2Ftls%2Flibc.so.6%22%2C%20O_RDONLY%7CO_CLOEXEC)%20%3D%20-1%20ENOSYS%20(Function%20not%20implemented)%20(INJECTED)%0Aopen(%22%2Flib%2Fx86_64-linux-gnu%2Fx86_64%2Flibc.so.6%22%2C%20O_RDONLY%7CO_CLOEXEC)%20%3D%20-1%20ENOSYS%20(Function%20not%20implemented)%20(INJECTED)%0Aopen(%22%2Flib%2Fx86_64-linux-gnu%2Flibc.so.6%22%2C%20O_RDONLY%7CO_CLOEXEC)%20%3D%20-1%20ENOSYS%20(Function%20not%20implemented)%20(INJECTED)%0Acat%3A%20error%20while%20loading%20shared%20libraries%3A%20libc.so.6%3A%20cannot%20open%20shared%20object%20file%3A%20Error%2038%0A%2B%2B%2B%20exited%20with%20127%20%2B%2B%2B”/]
- Count time, calls, and errors for each system call[pastacode lang=”markup” message=”” highlight=”” provider=”manual” manual=”%24%20strace%20-c%20ls%20%3E%20%2Fdev%2Fnull%0A%25%20time%20%20%20%20%20seconds%20%20usecs%2Fcall%20%20%20%20%20calls%20%20%20%20errors%20syscall%0A——%20———–%20———–%20———%20———%20—————-%0A%2089.76%20%20%20%200.008016%20%20%20%20%20%20%20%20%20%20%204%20%20%20%20%20%201912%20%20%20%20%20%20%20%20%20%20%20getdents%0A%20%208.71%20%20%20%200.000778%20%20%20%20%20%20%20%20%20%20%200%20%20%20%20%2011778%20%20%20%20%20%20%20%20%20%20%20lstat%0A%20%200.81%20%20%20%200.000072%20%20%20%20%20%20%20%20%20%20%200%20%20%20%20%20%208894%20%20%20%20%20%20%20%20%20%20%20write%0A%20%200.60%20%20%20%200.000054%20%20%20%20%20%20%20%20%20%20%200%20%20%20%20%20%20%20943%20%20%20%20%20%20%20%20%20%20%20open%0A%20%200.11%20%20%20%200.000010%20%20%20%20%20%20%20%20%20%20%200%20%20%20%20%20%20%20942%20%20%20%20%20%20%20%20%20%20%20close%0A%20%200.00%20%20%20%200.000000%20%20%20%20%20%20%20%20%20%20%200%20%20%20%20%20%20%20%20%201%20%20%20%20%20%20%20%20%20%20%20read%0A%20%200.00%20%20%20%200.000000%20%20%20%20%20%20%20%20%20%20%200%20%20%20%20%20%20%20944%20%20%20%20%20%20%20%20%20%20%20fstat%0A%20%200.00%20%20%20%200.000000%20%20%20%20%20%20%20%20%20%20%200%20%20%20%20%20%20%20%20%208%20%20%20%20%20%20%20%20%20%20%20mmap%0A%20%200.00%20%20%20%200.000000%20%20%20%20%20%20%20%20%20%20%200%20%20%20%20%20%20%20%20%204%20%20%20%20%20%20%20%20%20%20%20mprotect%0A%20%200.00%20%20%20%200.000000%20%20%20%20%20%20%20%20%20%20%200%20%20%20%20%20%20%20%20%201%20%20%20%20%20%20%20%20%20%20%20munmap%0A%20%200.00%20%20%20%200.000000%20%20%20%20%20%20%20%20%20%20%200%20%20%20%20%20%20%20%20%207%20%20%20%20%20%20%20%20%20%20%20brk%0A%20%200.00%20%20%20%200.000000%20%20%20%20%20%20%20%20%20%20%200%20%20%20%20%20%20%20%20%203%20%20%20%20%20%20%20%20%203%20access%0A%20%200.00%20%20%20%200.000000%20%20%20%20%20%20%20%20%20%20%200%20%20%20%20%20%20%20%20%201%20%20%20%20%20%20%20%20%20%20%20execve%0A%20%200.00%20%20%20%200.000000%20%20%20%20%20%20%20%20%20%20%200%20%20%20%20%20%20%20%20%201%20%20%20%20%20%20%20%20%20%20%20sysinfo%0A%20%200.00%20%20%20%200.000000%20%20%20%20%20%20%20%20%20%20%200%20%20%20%20%20%20%20%20%201%20%20%20%20%20%20%20%20%20%20%20arch_prctl%0A——%20———–%20———–%20———%20———%20—————-%0A100.00%20%20%20%200.008930%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2025440%20%20%20%20%20%20%20%20%203%20total”/]
Support Our Threat Intelligence
If you find our technology report and cybersecurity news helpful, consider supporting our work.