2017-11-27 25 views
0

타이머가 시작된 C++ 프로그램에서 bash nvme flush 명령을 실행하려고합니다. 이렇게하면 nvme 드라이버가 두 번째 타임 스탬프를 가져 와서 시간 계산을 수행하기 전에 모든 쓰기 작업을 완료 할 수 있습니다. 내 질문은 C++ system() 명령에 지정된 bash 명령이 C++ 프로그램의 다음 행 전에 실행되는지 여부입니다.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

예, system은 명령이 종료 될 때까지 대기합니다.

그렇지 않으면 일부 시스템에서처럼 프로그램의 리턴 값을 줄 수 없습니다. POSIX 시스템에서는 WEXITSTATUS을 사용하여이를 검색 할 수 있으므로 명령이 완료되어야합니다.

예를 here 것이 "시스템()가를 실행 말한다 : 컴퓨터가 man을 가지고 있으며, 해당 문서가 설치 한 경우

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

, 시스템이 컴퓨터에 동작하는 방법을 알아 man 3 system을 사용할 수 있습니다/bin/sh -c 명령을 호출하여 명령에 지정된 명령이고 은 명령이 완료된 후에 반환합니다. "