linux – strace:order of和<... resumed>

我正在编写一个脚本来分析用strace跟踪的文件访问.

跟踪包含一些已被另一个进程中断的调用. strace用< unfinished …>显示它们和< …关闭恢复> (如果是中断的近距离通话)标记.

[pid 26817] 12:48:22.972737 close(449 <unfinished ...>
[pid 28708] 12:48:22.972797 fcntl(451, F_SETFD, FD_CLOEXEC <unfinished ...>
[pid 26817] 12:48:22.972808 <... close resumed> ) = 0 

该进程及其所有线程都已被跟踪

strace -f -tt -p <pid>

手册页不确定呼叫何时结束.

If a system call is being executed and meanwhile another one is being called from a different thread/process then strace will try to preserve the order of those events and mark the ongoing call as being unfinished. When the call returns it will be marked as resumed.

虽然我假设,自然恢复的标记将指示呼叫现在已完成.我想问一下是不是这样.

可以将上面的跟踪摘录重建为

一个

[pid 28708] 12:48:22.972797 fcntl(451, F_SETFD, FD_CLOEXEC <unfinished ...>
[pid 26817] 12:48:22.972808 close(449) = 0

或者应该重建为

[pid 26817] 12:48:22.972737 close(449) = 0 
[pid 28708] 12:48:22.972797 fcntl(451, F_SETFD, FD_CLOEXEC <unfinished ...>

这里的顺序至关重要,因为未完成和恢复之间可能有多个调用,其中一个调用可能会对即将关闭的文件执行某些操作.

最佳答案 系统调用在strace写入行关闭时开始(449 ,并在输出< … close resumed>时结束.

任何其他调用或信号都不会中断关闭:另一个调用由另一个进程执行,而内核正在关闭文件描述符.

没有办法知道文件描述符关闭时的确切位置;你唯一知道的是,在系统调用执行之前它不会关闭,并且在系统调用完成时它会被关闭.

点赞