地方エンジニアの学習日記

興味ある技術の雑なメモだったりを書いてくブログ。たまに日記とガジェット紹介。

【eBPF】clone(2)のフラグとかPIDとかTIDとかを取りたい

というのをやりたかった過程で調べたメモ。これはちょっと便利そう。

bpftrace -e '
tracepoint:syscalls:sys_enter_clone
{
  printf("PID: %d, TID: %d, COMM: %s, clone_flags: 0x%lx\n", pid, tid, comm, args->clone_flags);

  if (args->clone_flags & 0x00000100) { printf("  CLONE_VM\n"); }
  if (args->clone_flags & 0x00000200) { printf("  CLONE_FS\n"); }
  if (args->clone_flags & 0x00000400) { printf("  CLONE_FILES\n"); }
  if (args->clone_flags & 0x00000800) { printf("  CLONE_SIGHAND\n"); }
  if (args->clone_flags & 0x00010000) { printf("  CLONE_THREAD\n"); }
  if (args->clone_flags & 0x00008000) { printf("  CLONE_PARENT\n"); }
  if (args->clone_flags & 0x10000000) { printf("  CLONE_NEWUSER\n"); }
  if (args->clone_flags & 0x20000000) { printf("  CLONE_NEWPID\n"); }
  if (args->clone_flags & 0x40000000) { printf("  CLONE_NEWNET\n"); }
  if (args->clone_flags & 0x00020000) { printf("  CLONE_NEWNS\n"); }
}
'

こんな感じで出力されます。

PID: 1369266, TID: 1369266, COMM: systemd-journal, clone_flags: 0x3d0f00
  CLONE_VM
  CLONE_FS
  CLONE_FILES
  CLONE_SIGHAND
  CLONE_THREAD