linux系统和windows系统检测磁盘大小报警
1.应用场景
需要往磁盘中存储图片和或者数据,需要检测磁盘大小,当小于5GB的时候提示用户,并停止存储图片和数据,避免磁盘塞满,无法启动系统或者操作电脑;
2.实现方法
用一个定时器去定时查询磁盘空间大小,linux系统,采用QProess执行命令,然后解析命令返回值,获取剩余的磁盘空间
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | void FaceMatch::SlotCheckDriverMemory() { ///磁盘名 QString strpicPath = CConfig::instance()->GetResaultPath(); #ifdef OS_WINDOWS QString iDriver = strpicPath.left(3); LPCWSTR strDriver = ( LPCWSTR )iDriver.utf16(); ULARGE_INTEGER freeDiskSpaceAvailable, totalDiskSpace, totalFreeDiskSpace; ///调用函数获取磁盘参数(单位为字节Byte) GetDiskFreeSpaceEx(strDriver, &freeDiskSpaceAvailable, &totalDiskSpace, &totalFreeDiskSpace); quint64 freeDB = totalFreeDiskSpace.QuadPart / (1024 * 1024 * 1024); m_VideoAnalysisTaskList->SlotSetStoreSpace(freeDB>=5); if (freeDB < 5) //space less than 5GB { if (m_bigThanFiveGB == true ) { m_bigThanFiveGB = false ; SlotError(-1, strpicPath + "磁盘空间不足5G,请在SystemConfig.xml配置文件切换磁盘,或者清除数据。" ); } else { m_bigThanFiveGB = false ; } } else //space big than 5GB { if (m_bigThanFiveGB == false ) //space { m_bigThanFiveGB = true ; m_VideoAnalysisTaskList->StartNextWaitTask( "struct" ); m_VideoAnalysisTaskList->StartNextWaitTask( "gait" ); SlotError(0, strpicPath + QString( "磁盘空间剩余%1,继续分析" ).arg(freeDB)); } } #else //获取保存的路径的 QProcess process; process.start( "df -h " + strpicPath); if (process.waitForFinished()) { QString bytes = process.readAll(); QString strLeftSize=bytes.split( "\n" ).at(1); QStringList list=strLeftSize.split( " " ); for ( int i=0;i<list.size();) { if (list[i]== " " ||list[i]== "" ) { list.removeAt(i); } else { i++; } } if (list.size()<4) { LOG_ERROR( "Get store info error:%s " ,bytes.toStdString().c_str()); return ; } strLeftSize=list[3]; strLeftSize= strLeftSize. remove ( "G" ); int freeDB =strLeftSize.toInt(); m_VideoAnalysisTaskList->SlotSetStoreSpace(freeDB >=5); if (freeDB<5) //space less than 5GB { if (m_bigThanFiveGB== true ) { m_bigThanFiveGB= false ; SlotError (-1, CConfig::instance()->GetResaultPath()+ "磁盘空间不足5G,请在SystemConfig.xml配置文件切换磁盘,或者清除数据。" ); } else { m_bigThanFiveGB= false ; } } else //space big than 5GB { if (m_bigThanFiveGB== false ) //space { m_bigThanFiveGB= true ; m_VideoAnalysisTaskList->StartNextWaitTask( "struct" ); m_VideoAnalysisTaskList->StartNextWaitTask( "gait" ); SlotError (0, CConfig::instance()->GetResaultPath() + QString( "磁盘空间剩余%1,继续分析" ).arg(freeDB)); } } } #endif } |
自己开发了一个股票智能分析软件,功能很强大,需要的关注微信公众号:QStockView
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
2021-10-12 centos防火墙操作firewalld and systemctl 打开linux端口的shell脚本
2021-10-12 Linux快速开发之makefile编译、以服务形式运行、抓包、调试、分析dump
2021-10-12 linux docker 操作命令