cmdref.net - Cheat Sheet and Example

cmdref.net is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools


Sidebar








Cloud



Etc


Reference














.

os:linux:command:strace.html



Linux Commands#Process Management

strace : How to use strace command in Linux with examples

man strace

NAME
       strace - trace system calls and signals


OPTIONS
       -p pid      Attach to the process with the process ID pid and begin tracing.  The trace may be terminated at any time
                   by a keyboard interrupt signal (CTRL-C).

       -t          Prefix each line of the trace with the time of day.

       -tt         If given twice, the time printed will include the microseconds.

       -f          Trace child processes as they are created by currently traced processes as a result of the fork(2) system
                   call.

       -s strsize  Specify the maximum string size to print (the default is 32).

       -c          Count time, calls, and errors for each system call and report a summary on program exit.


Example

$ strace COMMAND

$ strace ls /home
$ strace ls /hometest

$ strace -tt -s 1024 ls /home

$ strace -t -o test.txt php test.php

$ strace -tt -s 1024 -f -o /tmp/out.txt -e trace=stat  COMMAND
$ strace -tt -s 1024 -f -o /tmp/out.txt -e trace=wait4  COMMAND

Atache PID

$ strace -p  PID

$ strace -tt -s 1024 -f -p  PID
$ strace -tt -s 1024 -f -p  PID -e trace=stat

$ strace -tt -s 1024 -e execve -p PID

statistics

$ strace -c COMMAND
# strace -c ls /home
user01
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
100.00    0.000008           4         2         1 futex
  0.00    0.000000           0        10           read
  0.00    0.000000           0         1           write
  0.00    0.000000           0        12           open
  0.00    0.000000           0        14           close
  0.00    0.000000           0         1           stat
  0.00    0.000000           0        12           fstat
  0.00    0.000000           0        28           mmap
  0.00    0.000000           0        16           mprotect
  0.00    0.000000           0         3           munmap
  0.00    0.000000           0         3           brk
  0.00    0.000000           0         2           rt_sigaction
  0.00    0.000000           0         1           rt_sigprocmask
  0.00    0.000000           0         2           ioctl
  0.00    0.000000           0         1         1 access
  0.00    0.000000           0         1           execve
  0.00    0.000000           0         1           fcntl
  0.00    0.000000           0         2           getdents
  0.00    0.000000           0         1           getrlimit
  0.00    0.000000           0         1           statfs
  0.00    0.000000           0         1           arch_prctl
  0.00    0.000000           0         1           set_tid_address
  0.00    0.000000           0         1           set_robust_list
------ ----------- ----------- --------- --------- ----------------
100.00    0.000008                   117         2 total


How to strace Oracle Process

  1. Execute SQL/Plus
  2. How to Check Oracle PID
    SQL> select spid from v$process where addr=(select paddr from v$session where sid=SID);    <- your SID
    
  3. strace the oracle process
    $ strace -v -o /tmp/strace$$.log -ftt -p PID  <- your PID
    


Reference

UNIX System Calls

GENERAL CLASSSPECIFIC CLASSSYSTEM CALL Note
File Structure
Related Calls
Creating a Channel creat() If the file named by file_name does not exist, the UNIX system creates it with the specified mode permissions.
However, if the file does exist, its contents are discarded and the mode value is ignored.
open()open() lets you open a file for reading, writing, or reading and writing.
close()To close a channel, use the close() system call.
Input/Output read()
write()
Random Accesslseek() When used with the lseek() system call, they provide all the tools necessary to do input and output randomly.
Channel Duplicationdup() The dup() system call duplicates an open file descriptor and returns the new file descriptor.
Aliasing and Removing Files link()
unlink() unlink() is the only system call for removing a file in the UNIX system.
File Statusstat() stat() and fstat() return the information in the i-node for the file named by a string and by a file descriptor, respectively.
fstat()
Access Controlaccess()
chmod()
chown()
umask()
Device Controlioctl()
Process Related Calls Process Creation and Termination exec()
fork()
wait()
exit()
Process Owner and Groupgetuid()
geteuid()
getgid()
getegid()
Process Identitygetpid()
getppid()
Process Controlsignal()
kill()
alarm()
Change Working Directorychdir()
Interprocess Communication Pipelinespipe()
Messagesmsgget()
msgsnd()
msgrcv()
msgctl()
Semaphoressemget()
semop()
Shared Memoryshmget()
shmat()
shmdt()

UNIX System Calls







Linux Commands#Process Management




os/linux/command/strace.html.txt ยท Last modified: 2021/02/26 by admin

Page Tools