从 Solaris 中已运行的进程中捕获 stderr 和 stdout
我有一个当前正在运行的进程(arserverd),该进程是由用户“remedy”启动的。我能够以该用户身份登录。我想捕获 stderr 和 stdout 而无需重新启动进程。这可能吗?
I've got a process that is currently running (arserverd) that was started by user "remedy". I am able to log in as this user. I would like to capture stderr and stdout without restarting the process. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果该进程已在运行,您可以使用 truss 命令拦截对文件描述符 1 或 2 的写入:
Truss 将输出类似于
Truss 特定于 Solaris 的行。在 Linux 系统上,请查找
strace
。Truss 会稍微减慢您的桁架过程,因此您不想一直使用它。如果您正在寻找永久解决方案,最好的选择可能是在启动程序时将 stdout 和 stderr 重定向到文件。您可以定期截断文件以保持其大小易于管理。另一种方法是在
screen
会话中运行程序,当您想要与程序交互时可以重新连接到该会话。If the process is already running, you could use the
truss
command to intercept writes to file descriptor 1 or 2:Truss will output lines like
Truss is specific to Solaris. On linux systems, look for
strace
instead.Truss will slow down the process that you're trussing somewhat, so it's not something you'd want to use all the time. If you're looking for a permanent solution, your best bet is probably to redirect stdout and stderr to a file when launching the program. You can regularly truncate the file to keep its size manageable. An alternate is to run the program within a
screen
session that you can reconnect to when you want to interact with the program.我不这么认为,但您可以尝试从
/proc/PID/fd/1
中读取 stdout 并从/proc/PID/fd/2
中读取 stderr (替换PID
与进程的 PID)。I don't think so but you can try to read from
/proc/PID/fd/1
for stdout and/proc/PID/fd/2
for stderr (replacePID
with the PID of the process).