Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

20.3.4. SystemTap でのアプリケーションのシステム呼び出しの監視

SystemTap ツールでは、カーネルイベントにカスタムイベントハンドラーを登録できます。strace と比較すると、これは使いにくくなりますが、SystemTap はより効率的で、より複雑な処理ロジックを使用することができます。

前提条件
手順
  1. 以下の内容を含む my_script.stp ファイルを作成します。

    probe begin
    {
      printf("waiting for syscalls of process %d \n", target())
    }
    
    probe syscall.*
    {
      if (pid() == target())
        printf("%s(%s)\n", name, argstr)
    }
    
    probe process.end
    {
      if (pid() == target())
        exit()
    }
  2. 監視するプロセスのプロセス ID (pid) を検索します。

    $ ps -aux
  3. スクリプトで SystemTap を実行します。

    # stap my_script.stp -x pid

    pid の値は、プロセス ID です。

    スクリプトはカーネルモジュールにコンパイルされ、それが読み込まれます。これにより、コマンドの入力から出力の取得までにわずかな遅延が生じます。

  4. プロセスでシステム呼び出しが実行されると、呼び出し名とパラメーターがターミナルに出力されます。
  5. プロセスが終了した場合、または Ctrl+C を押すと、スクリプトは終了します。
関連資料