繁体   English   中英

C ++挂钟时间中的系统

[英]System in C++ Wall Clock Time

我正在尝试从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);

是的, system等待命令退出。

否则,它不能像某些系统上那样为您提供程序的返回值。 在POSIX系统上,可以使用WEXITSTATUS检索此内容,因此命令必须已完成。

http://en.cppreference.com/w/cpp/utility/program/system

如果您的计算机上安装了man并安装了适当的文档,则可以使用man 3 system来了解系统在您的计算机上的行为:

例如, 此处说“ system()通过调用/ bin / sh -c命令执行command中指定的命令,并在命令完成后返回 。”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM