USB flash disk data not transferred completely

We have one option in our application in QT to transfer the data to USB disk using system command as below

QProcess process;
QStringList args;
QDir dir("/media/sda1/");
dir.mkdir("ea1503");
args << "-c" << "tar czvf /media/sda1/ea1503/agd3100logfiles.tgz `find /home/root/log/*.agd -mtime -30`";
process.start("/bin/sh", args);
process.waitForFinished(-1); // will wait forever until finished

The function comes out of waitforfinished but complete data is not copied to USB disk. How we can ensure that the data is first flushed in USB and then waitforfinished.

Is there any command(QT/Linux) to flush the data to USB.

Is there any command(QT/Linux) to flush the data to USB.

Yes, that command is called sync. Find it’s manual here.

We have already treid the sync command after above code as below

QProcess process;
 QStringList args;
 args << "-c" << "sync";
 process.start("/bin/sh", args);
 process.waitForFinished(-1); // will wait forever until finished

But the process comes out of waitforfinished loop before actual data is transferred.

Dear @amolyp, can you confirm that there is data pending to be written? You can check in another terminal if the operations is being done with watch -n1 grep -e Dirty: -e Writeback: /proc/meminfo (Dirty being the total amount of memory, in kibibytes, waiting to be written back to the disk, and writeback, the total amount of memory, in kibibytes, actively being written back to the disk).

The watch command does show the data waiting to be written back to disk and data actively being written back to disk. However we want a command that will write the data immediately to flash disk.

Below is link to video showing how the qt application wait screen goes off before the complete data is written to flash disk.

Link to video

Hence when user removes the flash disk after wait screen goes off the complete data is not written to disk.

sync -d “filename” worked. Found details in “man sync” command. Thank you.