如何在不以超级用户身份运行的情况下从头开始跟踪程序 [英] How to trace a program from its very beginning without running it as root

查看:89
本文介绍了如何在不以超级用户身份运行的情况下从头开始跟踪程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个调用DTrace的工具,以跟踪用户指定的程序.

I'm writing a tool that calls through to DTrace to trace the program that the user specifies.

如果我的工具使用dtrace -c作为DTrace的子进程运行该程序,则不仅不能将任何参数传递给该程序,而且该程序还具有DTrace的所有特权-即以root身份运行(在Mac OS X上).这使得某些应该工作的事情中断了,并且显然使很多不应该工作的事情成为可能.

If my tool uses dtrace -c to run the program as a subprocess of DTrace, not only can I not pass any arguments to the program, but the program runs with all the privileges of DTrace—that is, as root (I'm on Mac OS X). This makes certain things that should work break, and obviously makes a great many things that shouldn't work possible.

我知道的另一种解决方案是自己启动程序,通过发送SIGSTOP暂停程序,将其PID传递给dtrace -p,然后通过发送SIGCONT继续执行.问题是在DTrace收集符号信息时该程序运行了几秒钟而没有被跟踪,或者,如果我在继续该过程之前睡了几秒钟,DTrace抱怨objc<pid>:<class>:<method>:entry没有匹配的探针.

The other solution I know of is to start the program myself, pause it by sending it SIGSTOP, pass its PID to dtrace -p, then continue it by sending it SIGCONT. The problem is that either the program runs for a few seconds without being traced while DTrace gathers the symbol information or, if I sleep for a few seconds before continuing the process, DTrace complains that objc<pid>:<class>:<method>:entry matches no probes.

有没有一种方法可以让我以用户的帐户而不是root身份运行该程序,但是DTrace仍然能够从头开始跟踪它?

Is there a way that I can run the program under the user's account, not as root, but still have DTrace able to trace it from the beginning?

推荐答案

类似sudo dtruss -f sudo -u <original username> <command>的东西对我有用,但后来我对此感到难过.

Something like sudo dtruss -f sudo -u <original username> <command> has worked for me, but I felt bad about it afterwards.

我提交了一个有关它的Radar错误,并将其作为#5108629的副本关闭了.

I filed a Radar bug about it and had it closed as a duplicate of #5108629.

这篇关于如何在不以超级用户身份运行的情况下从头开始跟踪程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆