如何检测某个功能是否执行IO操作?

时间:2018-07-27 14:22:31

标签: c++ unix io

我是否可以寻找任何指标来了解某个功能是否执行I / O操作? 主要目标平台是Linux(Ubuntu或它的某些变体)。

最明显的方法是拥有此类功能/库的目录,并检查其中是否存在该功能。但是,我想首先知道如何建立这样的目录。

例如,printf最终写入标准输出,因此它将计数。从USB端口读取的功能也将计数。但是,即使我必须深入到最低水平,它们也有共同点吗?


这个问题可能无关紧要,但是理想情况下,我可以利用这些功能的某种模式,以便可以使用工具自动识别它们。我只是不确定要查找什么低级指令。

1 个答案:

答案 0 :(得分:2)

标准C ++当然没有从USB读取的功能,但让我们暂时忽略该细节。

在标准C ++中,可以通过询问哪些库函数具有observable side effects来近似近似哪个函数执行“真实” I / O的问题。这直接指向Input/Output headers的集合,当然,如今也有<filesystem>

(从C ++复制参考:)

<iosfwd>    forward declarations of all classes in the input/output library
<ios>       std::ios_base class, std::basic_ios class template and several typedefs
<istream>   std::basic_istream class template and several typedefs
<ostream>   std::basic_ostream, std::basic_iostream class templates and several typedefs
<iostream>  several standard stream objects
<fstream>   std::basic_fstream, std::basic_ifstream, std::basic_ofstream class templates and several typedefs
<sstream>   std::basic_stringstream, std::basic_istringstream, std::basic_ostringstream class templates and several typedefs
<syncstream> (since C++20)  std::basic_osyncstream, std::basic_syncbuf, and typedefs
<strstream> (deprecated)    std::strstream, std::istrstream, std::ostrstream
<iomanip>   Helper functions to control the format of input and output
<streambuf> std::basic_streambuf class template
<cstdio>    C-style input-output functions
相关问题