[20181217]strace使用問題.txt
[20181217]strace使用問題.txt
--//最近使用starce跟蹤分析ogg相關程式遇到一些問題.
# strace -t -p 703 -f -e open,read,lseek
Process 703 attached with 12 threads - interrupt to quit
[pid 717] 15:07:01 read(22, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 717] 15:07:01 lseek(26, 2192071680, SEEK_SET) = 2192071680
[pid 720] 15:07:01 read(26, "\1\"\0\0.TA\0\337\20\0\0\20\200FZ`\0\0\0\4\0\6\0\177\354\237/\1\0\24\0"..., 1024000) = 1024000
[pid 717] 15:07:01 read(22, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 720] 15:07:01 read(26, "\1\"\0\0\376[A\0\325\20\0\0000\200\332\364G\225-\0\2\0\21\1\26\0\307\316\5\304\25-"..., 1024000) = 1024000
[pid 716] 15:07:03 read(18, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 716] 15:07:03 lseek(25, 1679056896, SEEK_SET) = 1679056896
[pid 719] 15:07:03 read(25, "\1\"\0\0000\n2\0\362\25\0\0000\200\0023(#\0\0k\0\21\0\306f\n\0\377\0\16\0"..., 1024000) = 1024000
[pid 716] 15:07:03 read(18, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 719] 15:07:03 read(25, "\1\"\0\0\0\0222\0\356\25\0\0\220\200\10I/5\300\0\214\303\24\0\0\200\6\0\373x\361."..., 1024000) = 1024000
[pid 717] 15:07:04 read(22, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 717] 15:07:04 lseek(26, 2192132608, SEEK_SET) = 2192132608
[pid 720] 15:07:04 read(26, "\1\"\0\0\245TA\0\337\20\0\0\20\200-3`\0\0\0\0043\6\0\305\356\237/\1\0ug"..., 1024000) = 1024000
[pid 717] 15:07:04 read(22, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 720] 15:07:04 read(26, "\1\"\0\0u\\A\0\325\20\0\0\230\200\214\205\0\0;V\2\r\2\0\5\0\377\377Y\310\300\21"..., 1024000) = 1024000
[pid 716] 15:07:06 read(18, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 716] 15:07:06 lseek(25, 1679399424, SEEK_SET) = 1679399424
[pid 719] 15:07:06 read(25, "\1\"\0\0\315\f2\0\362\25\0\0\34\200\265Q\0\0\313*\367\357\237/\6\0\0\0\0\0\0\0"..., 1024000) = 1024000
[pid 716] 15:07:06 read(18, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 716] 15:07:06 read(18, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 716] 15:07:06 read(18, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 719] 15:07:06 read(25, "\1\"\0\0\235\0242\0\356\25\0\0\20\200\177Z(\2\0\0\5\0\6\0009\231\361.\1\0\24\0"..., 1024000) = 1024000
[pid 703] 15:07:07 lseek(20, 0, SEEK_SET) = 0
[pid 717] 15:07:07 read(22, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 717] 15:07:07 lseek(26, 2192153600, SEEK_SET) = 2192153600
[pid 720] 15:07:07 read(26, "\1\"\0\0\316TA\0\337\20\0\0\20\200\347\257p\0\0\0\6\v\6\0\230\360\237/\1\0\0\0"..., 1024000) = 1024000
[pid 720] 15:07:07 read(26, "\1\"\0\0\236\\A\0\337\20\0\0008\200J75\0\22\0\240\212=\0\216\350@\1d\226;\0"..., 1024000) = 1024000
[pid 717] 15:07:07 read(22, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 717] 15:07:07 read(22, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
--//這樣可以跟蹤open,read,lseek函式.
--//如果我想儲存到檔案並且輸出,遇到問題:
# strace -t -p 703 -f -e open,read,lseek | tee /tmp/703.txt
...
--//ctrl+c中斷退出.
# ls -l /tmp/703.txt
-rw-r--r-- 1 root root 0 2018-12-17 15:07:51 /tmp/703.txt
--//可以發現這樣並不會透過管道寫入/tmp/703.txt,似乎starce的這些輸出被定向到標準錯誤輸出(控制程式碼2).
--//0對應標準輸入 1對應標準輸出 2對應標準錯誤.
--//改寫如下就ok了.
# strace -t -p 703 -f -e open,read,lseek 2>&1 | tee /tmp/703.txt
Process 703 attached with 12 threads - interrupt to quit
[pid 703] 15:18:26 lseek(20, 0, SEEK_SET) = 0
[pid 716] 15:18:26 read(18, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 716] 15:18:26 lseek(25, 1819684352, SEEK_SET) = 1819684352
[pid 719] 15:18:26 read(25, "\1\"\0\0\27;6\0\362\25\0\0l\200\312J\1\0\216\1\1\0\0\0\0\0\24\0k\0 \0"..., 1024000) = 1024000
[pid 716] 15:18:26 read(18, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 716] 15:18:26 read(18, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 716] 15:18:26 read(18, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 719] 15:18:26 read(25, "\1\"\0\0\347B6\0\356\25\0\0\20\200d\2040\2\0\0\5\0\6\0S\262\364.\1\0\360."..., 1024000) = 1024000
[pid 717] 15:18:27 read(22, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 717] 15:18:27 lseek(26, 2217297920, SEEK_SET) = 2217297920
[pid 720] 15:18:27 read(26, "\1\"\0\0\244\24B\0\337\20\0\0\300\200\"\323\0\0\0\0\2\2\1\0h5\242/\6\0\0\0"..., 1024000) = 1024000
[pid 720] 15:18:27 read(26, "\1\"\0\0t\34B\0\337\20\0\0x\200\25\262!\352\10\4\346\217\315\22\0\0\0\0\0\0\0\0"..., 1024000) = 1024000
[pid 720] 15:18:27 read(26, "\1\"\0\0D$B\0\337\20\0\0\20\200M\7/table></div>\r\n<"..., 1024000) = 1024000
[pid 720] 15:18:27 read(26, "\1\"\0\0\24,B\0\325\20\0\0`\200\346\3755px; left:435px;"..., 1024000) = 1024000
[pid 720] 15:18:27 read(26, "\1\"\0\0\3443B\0\325\20\0\0\200\200\217\1!j\t\4R0\331\22\0\0\0\0\0\0\0\0"..., 1024000) = 1024000
[pid 717] 15:18:27 read(22, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 717] 15:18:27 read(22, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
# cat /tmp/703.txt
Process 703 attached with 12 threads - interrupt to quit
[pid 703] 15:18:26 lseek(20, 0, SEEK_SET) = 0
[pid 716] 15:18:26 read(18, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 716] 15:18:26 lseek(25, 1819684352, SEEK_SET) = 1819684352
[pid 719] 15:18:26 read(25, "\1\"\0\0\27;6\0\362\25\0\0l\200\312J\1\0\216\1\1\0\0\0\0\0\24\0k\0 \0"..., 1024000) = 1024000
[pid 716] 15:18:26 read(18, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 716] 15:18:26 read(18, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 716] 15:18:26 read(18, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 719] 15:18:26 read(25, "\1\"\0\0\347B6\0\356\25\0\0\20\200d\2040\2\0\0\5\0\6\0S\262\364.\1\0\360."..., 1024000) = 1024000
[pid 717] 15:18:27 read(22, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 717] 15:18:27 lseek(26, 2217297920, SEEK_SET) = 2217297920
[pid 720] 15:18:27 read(26, "\1\"\0\0\244\24B\0\337\20\0\0\300\200\"\323\0\0\0\0\2\2\1\0h5\242/\6\0\0\0"..., 1024000) = 1024000
[pid 720] 15:18:27 read(26, "\1\"\0\0t\34B\0\337\20\0\0x\200\25\262!\352\10\4\346\217\315\22\0\0\0\0\0\0\0\0"..., 1024000) = 1024000
[pid 720] 15:18:27 read(26, "\1\"\0\0D$B\0\337\20\0\0\20\200M\7/table></div>\r\n<"..., 1024000) = 1024000
[pid 720] 15:18:27 read(26, "\1\"\0\0\24,B\0\325\20\0\0`\200\346\3755px; left:435px;"..., 1024000) = 1024000
[pid 720] 15:18:27 read(26, "\1\"\0\0\3443B\0\325\20\0\0\200\200\217\1!j\t\4R0\331\22\0\0\0\0\0\0\0\0"..., 1024000) = 1024000
[pid 717] 15:18:27 read(22, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 717] 15:18:27 read(22, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
---//簡單探究開啟控制程式碼的情況:
# ps -ef | grep strac[e]
root 1913 24587 1 15:18 pts/3 00:00:00 strace -t -p 703 -f -e open read lseek
# ls -l /proc/1913/fd
total 0
lrwx------ 1 root root 64 2018-12-17 15:19:40 0 -> /dev/pts/3
l-wx------ 1 root root 64 2018-12-17 15:19:40 1 -> pipe:[32398409]
l-wx------ 1 root root 64 2018-12-17 15:19:04 2 -> pipe:[32398409]
--//1,2 被定向到 pipe:[32398409].
# ps -ef | grep te[e]
root 1914 24587 0 15:18 pts/3 00:00:00 tee /tmp/703.txt
# ls -l /proc/1914/fd
total 0
lr-x------ 1 root root 64 2018-12-17 15:20:29 0 -> pipe:[32398409]
lrwx------ 1 root root 64 2018-12-17 15:20:29 1 -> /dev/pts/3
lrwx------ 1 root root 64 2018-12-17 15:19:04 2 -> /dev/pts/3
l-wx------ 1 root root 64 2018-12-17 15:20:29 3 -> /tmp/703.txt
--// 0 定向到pipe:[32398409],也就是接收strace的輸出.
# cat /proc/1914/fd/0
[pid 717] 15:21:36 read(22, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 717] 15:21:36 lseek(26, 2230129664, SEEK_SET) = 2230129664
[pid 720] 15:21:36 read(26,
[root@dbcndg2 IP=100.75 /proc/1691/fd 159]# cat /proc/1914/fd/0
[pid 717] 15:21:39 read(22, [pid 717] 15:21:39 lseek(26, 2230850560, SEEK_SET) = 2230850560
[pid 720] 15:21:39 read(26, "\1\"\0\0\n|B\0\337\20\0\0\20\200\20u`\0\0\0\4\211\6\0\373\367\242/\1\0\1\0"..., 1024000) = 1024000
[pid 717] 15:21:39 read(22, "\0\350\0\0\6\0\0\0\0\0\6\1\"R\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0"..., 32784) = 232
[pid 720] 15:21:39 read(26, "\1\"\0\0\332\203B\0\325\20\0\0X\200\27\330:normal;font-fam"..., 1024000) = 1024000
--//還有一種方式分別寫入檔案使用引數-ff
# strace -t -p 703 -ff -e open,read,lseek -o /tmp/703.txt
Process 703 attached with 12 threads - interrupt to quit
# ls -l /tmp/703.txt*
-rw-r--r-- 1 root root 88 2018-12-17 15:27:24 /tmp/703.txt.703
-rw-r--r-- 1 root root 0 2018-12-17 15:27:11 /tmp/703.txt.704
-rw-r--r-- 1 root root 0 2018-12-17 15:27:11 /tmp/703.txt.705
-rw-r--r-- 1 root root 0 2018-12-17 15:27:11 /tmp/703.txt.706
-rw-r--r-- 1 root root 0 2018-12-17 15:27:11 /tmp/703.txt.707
-rw-r--r-- 1 root root 0 2018-12-17 15:27:11 /tmp/703.txt.712
-rw-r--r-- 1 root root 0 2018-12-17 15:27:11 /tmp/703.txt.715
-rw-r--r-- 1 root root 2334 2018-12-17 15:27:30 /tmp/703.txt.716
-rw-r--r-- 1 root root 1815 2018-12-17 15:27:31 /tmp/703.txt.717
-rw-r--r-- 1 root root 0 2018-12-17 15:27:11 /tmp/703.txt.718
-rw-r--r-- 1 root root 1555 2018-12-17 15:27:30 /tmp/703.txt.719
-rw-r--r-- 1 root root 1090 2018-12-17 15:27:31 /tmp/703.txt.720
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2285470/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20190314]使用strace注意的問題.txt
- [20200402]strace過濾使用awk問題.txt
- [20181217]ogg抽取日誌分析.txt
- [20210303]bbed使用小問題.txt
- [20181227]bbed的使用問題.txt
- [20210902]cut使用輸出問題.txt
- [20200227]使用tcpdump or and ()語法問題.txtTCP
- [20221010]使用toad管理索引改名問題.txt索引
- [20191118]使用Chrome瀏覽器問題.txtChrome瀏覽器
- [20220324]toad與sql profile使用問題.txtSQL
- [20181119]使用sql profile優化問題.txtSQL優化
- [20180412]logminer使用問題(10g).txt
- [20221101]tmux使用問題copy和paste失效.txtUXAST
- [20211220]記錄使用sqlplus的小問題.txtSQL
- [20190221]使用nmap掃描埠的問題.txt
- [20180420]windows下使用cmd的小問題.txtWindows
- Oracle最佳化案例-strace sqlplus定位網路問題(三十一)OracleSQL
- strace解決sqlplus登陸緩慢的問題一例SQL
- [20200219]strace跟蹤設定ENABLE=BROKEN的情況.txt
- [20240309]在windwos下使用sed遇到的問題.txt
- [20220517]toad使用gather_plan_statistics提示問題.txt
- [20210929]sql打補丁使用rule提示問題.txtSQL
- [20181006]12c使用toad連線問題.txt
- [20210812]windows xcopy問題.txtWindows
- [20190221]sql patch 問題.txtSQL
- [20181204]bbed修改問題.txt
- [20190313]備份問題.txt
- [20180619]bbed verify問題.txt
- [20231029]使用cygwin調式bash shell引出的問題.txt
- [20231101]使用tpt seg2.sql指令碼問題.txtSQL指令碼
- [20190929]bash使用bc計算的相關問題.txt
- [20191202]關於oracle例項是否使用hugepages問題.txtOracle
- [20220102]使用ashtop與dashtop指令碼的小問題.txt指令碼
- [20211221]記錄使用sqlplus的小問題補充.txtSQL
- [20190320]關於使用smem檢視記憶體使用的問題.txt記憶體
- 使用strace來查詢php的坑PHP
- [20241110]使用xto10.sql指令碼遇到的問題.txtSQL指令碼
- [20221203]sqlplus set trimspool 問題.txtSQL