Linux Commands#Process Management
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.
$ 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
$ 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
$ 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
SQL> select spid from v$process where addr=(select paddr from v$session where sid=SID); <- your SID
$ strace -v -o /tmp/strace$$.log -ftt -p PID <- your PID
| GENERAL CLASS | SPECIFIC CLASS | SYSTEM 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 Access | lseek() | When used with the lseek() system call, they provide all the tools necessary to do input and output randomly. | |
| Channel Duplication | dup() | 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 Status | stat() | 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 Control | access() | ||
| chmod() | |||
| chown() | |||
| umask() | |||
| Device Control | ioctl() | ||
| Process Related Calls | Process Creation and Termination | exec() | |
| fork() | |||
| wait() | |||
| exit() | |||
| Process Owner and Group | getuid() | ||
| geteuid() | |||
| getgid() | |||
| getegid() | |||
| Process Identity | getpid() | ||
| getppid() | |||
| Process Control | signal() | ||
| kill() | |||
| alarm() | |||
| Change Working Directory | chdir() | ||
| Interprocess Communication | Pipelines | pipe() | |
| Messages | msgget() | ||
| msgsnd() | |||
| msgrcv() | |||
| msgctl() | |||
| Semaphores | semget() | ||
| semop() | |||
| Shared Memory | shmget() | ||
| shmat() | |||
| shmdt() |