0

I have some difficulty understanding the -D option of strace. strace manpage says

-D Run tracer process as a detached grandchild, not as parent of the tracee. This reduces the visible effect of strace by keeping the tracee a direct child of the calling process.

Is "tracer process" the process which runs strace?

Is "calling process" the parent process of the "tracer process"?

What are the parent-child relations between the tracer, tracee and calling processes, without -D and with -D?

Thanks!

3

The tracer process is the process which runs strace, yes. The calling process is the process which starts strace, so typically your shell.

Without -D, the traced process’ parent ends up being strace:

strace sleep 120

shows up in pstree as

-───zsh───strace───sleep

With -D, strace detaches itself and ends up being re-parented, on my system to my user systemd process:

    |-systemd-+-(sd-pam)
   ...
    |         |-gnome-terminal--+-3*[zsh]
    |         |                 |-zsh---sleep
   ...
    |         |-strace

The impact of the -D option is briefly described in the strace man page:

Note that parent-child relationship (signal stop notifications, getppid() value, etc) between traced process and its parent are not preserved unless -D is used.

Running with -D means that the child will find its expected parent when it calls getppid(), and it also makes SIGCHLD behave correctly when the child is stopped and continued. This can be important in circumstances where you insert strace between a process and its children, when its children need to find their parent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.