Failed to execute script.sh: unknown error

故事扮演 提交于 2019-12-06 07:52:42

Thanks to the tip to which @l'L'l linked: I was able to work around this.

You'll need two shells.

In shell A (the shell we'll be inspecting):

# copy this shell's PID to clipboard (93827 for this example)
echo $$ | pbcopy

In shell B (the shell which will run DTrace), start tracing that PID:

sudo dtrace -n 'syscall:::entry
/progenyof($1) && pid != $1/
{
    @[probefunc] = count();
}' 93827

We use progenyof() to ensure that we trace child processes of the shell. I've added && pid != $1 since for some reason progenyof(x) seems to include x.

Now back in shell A, run some code you'd like to inspect:

grep 1 <<< 123

Our DTrace program in shell B will successfully catch the child process launched in shell A.

There's a bit of noise to sift through. Maybe the shell launches a variety of children. Not sure how to be more selective.


It's educational to look at how dtruss implements -f ("follow children as they are forked")...

less "$(which dtruss)"

Relevant clauses are those using an OPT_follow && filter (indicates that -f is enabled) or the self->child variable (indicates that this thread is a child of the process specified in -p PID).

It's also useful to know that ppid is a built-in variable which gives you the parent PID.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!