C ++挂钟时间系统

时间:2017-11-27 15:41:01

标签: c++ bash system

我正在尝试使用已经启动的计时器从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);

0 个答案:

没有答案