Home arrow Journal arrow Trace the system calls in FreeBSD with truss
Trace the system calls in FreeBSD with truss PDF
Wednesday, 18 April 2012
If you want to trace the system calls in FreeBSD there's truss utility, which is equivalent to Linux's strace tool.

For example we could run:

  truss /bin/ls

Or, let's say we have the simplest possible C program:

hello.c
#include <stdio.h>

int main(void)
{
  printf("Hello World");
  return 0;
}

We compile it:

  gcc hello.c -o hello

Then we run truss on it:

  truss ./hello

You will get something like this:

truss output on hello binary
mmap(0x0,32768,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34366255104 (0x800637000)
issetugid(0x800638015,0x800848cb8,0x800848c88,0x800848ca8,0x887a,0x0)
 = 0 (0x0)
open("/etc/libmap.conf",O_RDONLY,0666)           ERR#2 'No such file or directory'
open("/var/run/ld-elf.so.hints",O_RDONLY,00)     = 3 (0x3)
read(3,"Ehnt\^A\0\0\0\M^@\0\0\0\M-]\^A\0"...,128) = 128 (0x80)
lseek(3,0x80,SEEK_SET)                           = 128 (0x80)
read(3,"/lib:/usr/lib:/usr/lib/compat:/u"...,477) = 477 (0x1dd)
close(3)                                         = 0 (0x0)
access("/lib/libc.so.7",0)                       = 0 (0x0)
open("/lib/libc.so.7",O_RDONLY,030737770)        = 3 (0x3)
fstat(3,{ mode=-r--r--r-- ,inode=158432,size=1233976,blksize=32768 }) =
 0 (0x0)
SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|
SIGIO|SIGXCPU|
SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|
SIGUSR2,0x0) = 0 (0x0)
sigprocmask(SIG_SETMASK,0x0,0x0)                 = 0 (0x0)
fstat(1,{ mode=crw------- ,inode=178,size=0,blksize=4096
}) = 0 (0x0)
readlink("/etc/malloc.conf",0x7fffffffcc00,1024) ERR#2
'No such file or directory'

issetugid(0x80093d58a,0x7fffffffcc00,0xffffffffffffffff,0x2,
0xffff800800b6dd20,
0x8080808080808080) = 0 (0x0)
SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|
SIGINFO|SIGUSR1|
SIGUSR2,0x0) = 0 (0x0)
sigprocmask(SIG_SETMASK,0x0,0x0)                 = 0 (0x0)
Hello Worldwrite(1,"Hello World",11)                     = 11 (0xb)
process exit, rval = 0


Last Updated ( Wednesday, 18 April 2012 )
 
< Prev   Next >

Other BSD Systems

OpenBSD

Misc

Solaris

Polls

Best BSD firewall?