インフラ系SEの技術メモ

雑なエンジニアが低信頼性のメモを書いています。参考程度にとどめてください。

(Linux)straceって動いているプロセスを指定することもできるんですね

システムコールを見るコマンド

straceはコマンドの前につけるとそのコマンドの動きの

$ strace ls
--- Process 18596 created
--- Process 18596 loaded C:\Windows\System32\ntdll.dll at 00007ffa22890000
--- Process 18596 loaded C:\Windows\System32\kernel32.dll at 00007ffa20bf0000
--- Process 18596 loaded C:\Windows\System32\KernelBase.dll at 00007ffa20110000
--- Process 18596 thread 11272 created
--- Process 18596 thread 1408 created
--- Process 18596 loaded C:\cygwin64\bin\cygwin1.dll at 0000000180040000
--- Process 18596 loaded C:\cygwin64\bin\cygintl-8.dll at 00000003fef90000
--- Process 18596 thread 18960 created
--- Process 18596 loaded C:\cygwin64\bin\cygiconv-2.dll at 00000003ff020000
    0       0 [main] ls (18596) **********************************************
  246     246 [main] ls (18596) Program name: C:\cygwin64\bin\ls.exe (windows pid 18596)
  181     427 [main] ls (18596) OS version:   Windows NT-10.0
  166     593 [main] ls (18596) **********************************************

ハイフンpで任意のプロセスを選べた

pidを指定するオプションがあります。

-p, --pid=n                  attach to executing program with cygwin pid n

というわけでプロセスを作って

$ sleep 200&
[1] 860

それを覗くことができるというわけですね。

$ strace -p 860
--- Process 9604 (pid: 860) created
Windows process 9604 attached
--- Process 9604 (pid: 860) loaded C:\Windows\System32\ntdll.dll at 00007ffa22890000
...

これは便利。