Monday, June 13, 2011

Understanding how a linux command work internally

You can use strace command to understanding how a linux command work internally. For example, to check on the date command

# strace -c /bin/date

strace is a system call monitor command and provides information about system calls made by an application, including the call arguments and return value.

% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
   nan    0.000000           0         5           read
   nan    0.000000           0         1           write
   nan    0.000000           0        36        30 open
   nan    0.000000           0         7           close
   nan    0.000000           0        14         9 stat
   nan    0.000000           0         8           fstat
   nan    0.000000           0         1           lseek
   nan    0.000000           0        16           mmap
   nan    0.000000           0         7           mprotect
   nan    0.000000           0         3           munmap
   nan    0.000000           0         3           brk
   nan    0.000000           0         2           rt_sigaction
   nan    0.000000           0         1           rt_sigprocmask
   nan    0.000000           0         1         1 access
   nan    0.000000           0         1           execve
   nan    0.000000           0         1           uname
   nan    0.000000           0         1           getrlimit
   nan    0.000000           0         1           arch_prctl
   nan    0.000000           0         1           futex
   nan    0.000000           0         1           set_tid_address
   nan    0.000000           0         1           clock_gettime
   nan    0.000000           0         1           set_robust_list
------ ----------- ----------- --------- --------- ----------------
100.00    0.000000                   113        40 total

No comments: