the*_*ear 23 macos cron stdout process capture
我有一个正在运行的cron工作,它将持续一段时间,我想查看它的stdout.我不知道这个过程是由cron启动的重要性,但我想我会提到它.这是在OSX上,所以,我无法访问像.../proc/[pid]/...,或truss,或strace这样的东西.使用IO重定向(例如script > output & tail -f output)执行的建议是不可接受的,因为此过程已经1)已经运行,并且2)无法通过重定向停止/重新启动.如果有一些通用解决方案适用于各种Unices,那将是理想的,但具体而言我现在正试图在Mac上实现这一点.
mpy*_*pyw 39
将以下功能写入您的~/.bashrc或~/.zshrc.
capture() {
sudo dtrace -p "$1" -qn '
syscall::write*:entry
/pid == $target && arg0 == 1/ {
printf("%s", copyinstr(arg1, arg2));
}
'
}
Run Code Online (Sandbox Code Playgroud)
用法:
example@localhost:~$ perl -e 'STDOUT->autoflush; while (1) { print "Hello\n"; sleep 1; }' >/dev/null &
[1] 97755
example@localhost:~$ capture 97755
Hello
Hello
Hello
Hello
...
Run Code Online (Sandbox Code Playgroud)
https://github.com/mivok/squirrelpouch/wiki/dtrace
注意:
您必须禁用dtraceEl Capitan或更高版本的限制.
csrutil enable --without dtrace
Run Code Online (Sandbox Code Playgroud)
Mar*_*ouf 20
免责声明:如果Mac有这个,那就不清楚了.这种技术存在于Linux上.因人而异.
你可以从/ proc获取stdout/err(假设有适当的权限):
PID=$(pidof my_process)
tail -f /proc/$PID/fd/1
Run Code Online (Sandbox Code Playgroud)
或者将缓冲区中剩余的所有内容都抓取到文件中:
cat /proc/$PID/fd/1
Run Code Online (Sandbox Code Playgroud)
PS:fd/1是stdout,fd/2是stderr.
编辑:亚历克斯布朗> Mac没有这个,但它是Linux的一个有用的提示.
使用dtruss -p <PID>,甚至rwsnoop -p <PID>。
| 归档时间: |
|
| 查看次数: |
18173 次 |
| 最近记录: |