[問題] 即時偵測檔案變動
看板C_and_CPP (C/C++)作者ireullin (raison detre)時間14年前 (2012/05/07 11:35)推噓2(2推 0噓 7→)留言9則, 7人參與討論串1/2 (看更多)
請問一下各位
要如何及時得知檔案有被更動呢
我使用的是select的方式
但是執行結果卻是一直回傳true
如果採用檢查檔案大小或是md5的方式
卻又必須一值loop他,吃掉了太多的系統資源
如果加了sleep,又不是真正的"即時"
請問大家都怎麼做呢
bool FileIO::IsModified(double waitsecond)
{
FD_ZERO(&m_set);
FD_SET(m_fd, &m_set);
double _sec = floor(waitsecond);
struct timeval timeout;
timeout.tv_sec = (long)_sec;
timeout.tv_usec = (long)(waitsecond-_sec)*1000*1000;
int _rc = ::select(FD_SETSIZE, &m_set, NULL, NULL, &timeout);
if(_rc<0)
return false;
//throw "select failed";
if(_rc==0)
return false;
if(FD_ISSET( m_fd, &m_set)<=0 )
return false;
return true;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.220.71.34
→
05/07 11:36, , 1F
05/07 11:36, 1F
→
05/07 12:01, , 2F
05/07 12:01, 2F
→
05/07 12:24, , 3F
05/07 12:24, 3F
→
05/07 12:40, , 4F
05/07 12:40, 4F
推
05/07 12:40, , 5F
05/07 12:40, 5F
→
05/07 12:42, , 6F
05/07 12:42, 6F
→
05/07 13:24, , 7F
05/07 13:24, 7F
推
05/07 14:44, , 8F
05/07 14:44, 8F
→
05/07 21:55, , 9F
05/07 21:55, 9F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章