Отслеживание системных вызовов

668
ddmichael

Я пытаюсь научиться некоторым трюкам, используя «trace» (или dtrace, или strace, или truss), поэтому я использую команду:

trace -d [random PID] 

Я получаю следующие сообщения об ошибках:

ошибка трассировки: ошибка средства трассировки, KERN_KDREMOVE: в доступе отказано

или же

Не удалось открыть файл описания кода [PID]

Я не уверен насчет флага и, вероятно, отличается в других ОС (я использую MacOS с ядром Darwin), но основные функции должны быть такими же.

Может ли кто-нибудь предоставить краткое руководство по этому инструменту?

1

1 ответ на вопрос

2
miklosq

do you want to strace an already running process? At least on Linux (with root permission), you can try the following to attach to a Bash shell prompt process.

# strace -p [PID of a process] Process 2055 attached read(0, 

And it's waiting there. The option -p is the one that attaches to a running process. With the option -d, you can get strace to display debug information from itself.

See the strace (1) manual,

" -d Show some debugging output of strace itself on the standard error. "

Without root permission, you'll get similar errors, like the following on an Ubuntu 13.10:

$ strace -p [random PID] strace: attach: ptrace(PTRACE_ATTACH, ...): Operation not permitted Could not attach to process. If your uid matches the uid of the target process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try again as the root user. For more details, see /etc/sysctl.d/10-ptrace.conf 

Похожие вопросы