1 Star2 Stars3 Stars4 Stars5 Stars (1评分, 平均分: 5.00)
Loading...

DTrace中的progenyof()函数

关于progenyof()函数的介绍

int progenyof(pid_t pid)

progenyof returns non-zero if the calling process (the process associated with the thread that is currently triggering the matched probe) is among the progeny of the specified process ID.

也就是当前触发probe的进程是progenyof()参数pid的“子孙进程”,progenyof()返回非0值;反正返回0。参考下面例子(运行在FreeBSD系统上):

# cat progeny.d
#!/usr/sbin/dtrace -qs
BEGIN
{
        printf("%-10s%-8s\n", "ancestor", "child");
}
proc:::create
/progenyof($1)/
{
        printf("%-10i%-8i\n", pid, args[0]->p_pid);
}

打开一个shell会话,得到当前shell进程ID

# echo $$
2674

在另外一个shell会话运行上面的progeny.d脚本,追踪第一个shell会话产生的进程:

 # ./progeny.d 2674

在第一个shell中执行命令,“./progeny.d 2674”会产生下列输出:

# ./progeny.d 2674
ancestor  child
2674      2748
2674      2749

参考资料:
DTrace Bugs on Mac

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.