【发布时间】:2017-11-27 15:41:01
【问题描述】:
我正在尝试从已启动计时器的 C++ 程序运行 bash nvme flush 命令。这是为了让 nvme 驱动程序在获取第二个时间戳并执行时间计算之前完成对驱动器的所有写入。我的问题是 C++ system() 命令中指定的 bash 指令是否会在 C++ 程序的下一行之前执行。
fd = open (fname.c_str (), O_WRONLY | O_CREAT, 0660);
// Verify the file has been opened.
if (fd == -1)
{
cout << get_datetime_string() << "Write open of " << fname
<< " failed. Errno: " << errno << endl;
}
else
{
// Total bytes written.
uint64_t written = 0;
// Notify the start of the test.
cout << get_datetime_string() << "Write test started" << endl;
// Elapsed time.
struct timeval tv = { 0 };
get_elapsed_time (&tv);
struct timeval write_tv = tv;
// Run until it is time for the test to stop.
while (written < READ_LIMIT && zero_writes < 10)
{
ssize_t writesize = write (fd, &buf[0], blocksize);
if (writesize == -1)
{
cout << get_datetime_string << "Write failure. Errno: " << errno << endl;
zero_writes = 10;
}
else if (0 == writesize)
{
cout << get_datetime_string() << "Zero bytes written" << endl;
zero_writes++;
}
else
{
written += writesize;
}
}
//
// ISSUE THE NVME FLUSH COMMAND HERE
// Something like system("nvme flush...");
//
// Get the elapsed time.
get_elapsed_time (&write_tv);
【问题讨论】: