如何仅针对特定进程名称过滤系统调用列表?

How to filter list of syscalls only to specific process name?

我有以下 dtrace 一行代码:

sudo dtrace -n 'syscall:::entry { @num[probefunc] = count(); }'

它按程序打印系统调用计数(在点击 Ctrl-C.

如何在探测器上方添加过滤器以仅按名称应用于进程(例如 php)?类似于 dtruss -n <name>.

好的,这很简单,因为可以在 dtruss 中检查过滤是如何完成的:

$ grep -C5 NAME $(which dtruss)
syscall:::entry
/(OPT_command && pid == $target) || 
 (OPT_pid && pid == PID) ||
 (OPT_name && NAME == strstr(NAME, execname)) ||
 (OPT_name && execname == strstr(execname, NAME)) ||
 (self->child)/
{
  /* set start details */

其中 NAME 是进程名称。

所以一行命令是(将php替换为您的进程名称):

sudo dtrace -n '
  inline string NAME = "php";
  syscall:::entry
  /(NAME == strstr(NAME, execname)) || (execname == strstr(execname, NAME))/
{ @num[probefunc] = count(); }
'