以下面脚本(hello.d
)为例,讲述执行DTrace
脚本的方法:
BEGIN
{
/* This is a C-style comment */
trace("hello, world");
exit(0);
}
(1)在命令行运行dtrace -s hello.d
命令:
# dtrace -s hello.d
dtrace: script 'hello.d' matched 1 probe
CPU ID FUNCTION:NAME
0 1 :BEGIN hello, world
(2)在脚本第一行加上“#!/usr/sbin/dtrace -s
”:
#!/usr/sbin/dtrace -s
BEGIN
{
/* This is a C-style comment */
trace("hello, world");
exit(0);
}
在命令行直接执行hello.d
即可:
# ./hello.d
dtrace: script './hello.d' matched 1 probe
CPU ID FUNCTION:NAME
0 1 :BEGIN hello, world