2

保存的bag在断电重启后大小变为0

 8 months ago
source link: https://charon-cheung.github.io/2023/12/19/%E9%82%A3%E4%BA%9B%E5%8D%A1%E6%88%91%E5%BE%88%E4%B9%85%E7%9A%84bug/%E4%BF%9D%E5%AD%98%E7%9A%84bag%E5%9C%A8%E6%96%AD%E7%94%B5%E9%87%8D%E5%90%AF%E5%90%8E%E5%A4%A7%E5%B0%8F%E4%B8%BA0/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

保存的bag在断电重启后大小变为0 | 沉默杀手

保存的bag在断电重启后大小变为0
2023-12-19|那些卡我很久的bug|
Word count: 233|Reading time: 1 min

程序保存了bag文件,在退出程序后,bag是正常的,但是断电重启开发板后,发现bag还存在,但是大小为0. 如果是使用reboot重启,bag仍然正常。如果把bag复制一个,断电重启后,复制的bag大小也是0

boost::filesystem::exists判断文件为不存在,但是用ls是能看到的

断电瞬间应该不再向磁盘写文件了

内容丢失: Linux为延迟写(delayedwrite),突然断电时,文件缓冲区中数据还未写入文件,导致文件大小为 0

加入flush函数,保证所有输出第一时间写入文件,防止数据丢失。 write函数只是将所写内容存入用户缓存,并不立刻写入文件. close函数则先执行flush, 再关闭文件的读写.

所以最好在程序里调用write后,紧接着执行close

©2018 - 2023 By Charon Cheung
Driven - Hexo|Theme - Melody

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK