previous contents up next

Unix for Advanced Users

15. Advanced Commands and Usage

15.8. (strace), (truss), and (par)

The UNIX strace program (or truss under Solaris, and par under IRIX) is essential for debugging many system problems. strace is a system call tracer and displays each system call a process performs and the arguments passed. strace can spawn a new program to trace, or it can be invoked on an existing process.

There are many instances when a program freezes or otherwise fails to work, and offers few clues as to the problem. Sometimes a daemon process fails to perform its duty. Occasionally you may need to spy on the workings of a network program to see what order it opens sockets, or reads configuration files. strace is great for these occasions.

strace is invoked with the program to be traced as the argument, or with the "-p" option with a PID number to trace a process that is already running. The "-s" option to set the string size is highly recommended if you need to examine the input and output of a program.

Here is an example of running truss under Solaris to trace all the system calls made by the command "ls":

solaris% truss ls

execve("/usr/bin/ls", 0xEFFFFD20, 0xEFFFFD28)  argc = 1
open("/dev/zero", O_RDONLY)			= 3
mmap(0x00000000, 8192, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0xEF7C0000
open("/usr/lib/libw.so.1", O_RDONLY)		= 4
fstat(4, 0xEFFFF9D4)				= 0
mmap(0x00000000, 8192, PROT_READ|PROT_EXEC, MAP_SHARED, 4, 0) = 0xEF7B0000
mmap(0x00000000, 98304, PROT_READ|PROT_EXEC, MAP_PRIVATE, 4, 0) = 0xEF790000
munmap(0xEF798000, 57344)			= 0
mmap(0xEF7A6000, 3512, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 4, 24576) = 0xEF7A6000
close(4)					= 0
open("/usr/lib/libintl.so.1", O_RDONLY)		= 4
fstat(4, 0xEFFFF9D4)				= 0
mmap(0xEF7B0000, 8192, PROT_READ|PROT_EXEC, MAP_SHARED|MAP_FIXED, 4, 0) = 0xEF7B0000
mmap(0x00000000, 81920, PROT_READ|PROT_EXEC, MAP_PRIVATE, 4, 0) = 0xEF770000
munmap(0xEF774000, 57344)			= 0
mmap(0xEF782000, 3040, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 4, 8192) = 0xEF782000
close(4)					= 0
open("/usr/lib/libc.so.1", O_RDONLY)		= 4
fstat(4, 0xEFFFF9D4)				= 0
mmap(0xEF7B0000, 8192, PROT_READ|PROT_EXEC, MAP_SHARED|MAP_FIXED, 4, 0) = 0xEF7B0000
mmap(0x00000000, 622592, PROT_READ|PROT_EXEC, MAP_PRIVATE, 4, 0) = 0xEF680000
munmap(0xEF700000, 57344)			= 0
mmap(0xEF70E000, 29088, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 4, 516096) = 0xEF70E000
mmap(0xEF716000, 5104, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0xEF716000
close(4)					= 0
open("/usr/lib/libdl.so.1", O_RDONLY)		= 4
fstat(4, 0xEFFFF9D4)				= 0
mmap(0xEF7B0000, 8192, PROT_READ|PROT_EXEC, MAP_SHARED|MAP_FIXED, 4, 0) = 0xEF7B0000
close(4)					= 0
open("/usr/platform/SUNW,Ultra-2/lib/libc_psr.so.1", O_RDONLY) = 4
fstat(4, 0xEFFFF834)				= 0
mmap(0x00000000, 8192, PROT_READ|PROT_EXEC, MAP_SHARED, 4, 0) = 0xEF760000
mmap(0x00000000, 81920, PROT_READ|PROT_EXEC, MAP_PRIVATE, 4, 0) = 0xEF740000
munmap(0xEF744000, 57344)			= 0
mmap(0xEF752000, 5440, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 4, 8192) = 0xEF752000
close(4)					= 0
close(3)					= 0
munmap(0xEF760000, 8192)			= 0
time()						= 932140546
ioctl(1, TCGETA, 0xEFFFFC4C)			Err#25 ENOTTY
brk(0x000244E8)					= 0
brk(0x000264E8)					= 0
brk(0x000264E8)					= 0
brk(0x0002E4E8)					= 0
lstat(".", 0xEFFFFBD8)				= 0
open(".", O_RDONLY|O_NDELAY)			= 3
fcntl(3, F_SETFD, 0x00000001)			= 0
fstat(3, 0xEFFFFB18)				= 0
getdents(3, 0x0002D110, 1048)			= 368
getdents(3, 0x0002D110, 1048)			= 0
close(3)					= 0
ioctl(1, TCGETA, 0xEFFFDE2C)			Err#25 ENOTTY
fstat(1, 0xEFFFDEA0)				= 0
brk(0x0002E4E8)					= 0
brk(0x000304E8)					= 0
lseek(0, 0, SEEK_CUR)				= 91149
AWK.html
GREP.html
RCS
SED.html
dd.html
index.html
lsof.html
od.html
pipe.html
regexp.html
sevregexp
su.html
sudo.html
truss.html
truss.html.swp
truss.html~
write(1, " A W K . h t m l\n G R E".., 157)	= 157
_exit(0)

previous contents up next