1 Star2 Stars3 Stars4 Stars5 Stars (还没有评分)
Loading...

DTrace脚本运行时参数

Shell脚本类似,DTrace脚本也可以接收运行时参数:$0扩展为脚本名,$1扩展为第一个参数,$2扩展为第二个。。。Macro Arguments文档提供了一个tracewrite.d例子:

#!/usr/sbin/dtrace -s

syscall::write:entry
/pid == $1/
{
}

需要注意的是如果在脚本中使用了$1$2这些参数,在执行脚本时一定要提供这些参数:

# ./tracewrite.d 123

否则直接运行脚本就会报出如下错误:

# ./tracewrite.d
dtrace: failed to compile script ./tracewrite.d: line 4: macro
argument $1 is not defined

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.