對於應用程式,有時候可能需要判斷某個檔案是否已經被開啟,也就是指是否被某個流連接著。這在對檔案的讀寫比較頻繁的程式中尤為重要,因為乙個檔案同一時刻只能有乙個流連線的。下面的**也許能有所幫助。
[csharp]view plain
copy
print?
public
class
filestatus
intptr handle = _lopen(filefullname, of_readwrite | of_share_deny_none);
if(handle == hfile_error)
closehandle(handle);
return
0;
} }
測試:[csharp]view plain
copy
print?
class
program
{ static
void
main(
string
args)
{ string
"testopen.txt"
; filestream fs = new
filestream(testfilepath, filemode.openorcreate, fileaccess.read);
binaryreader br = new
binaryreader(fs);
br.read();
console.writeline("檔案被開啟"
);
intresult =filestatus.fileisopen(testfilepath);
console.writeline(result);
br.close();
結果:
保持numlock處於開啟狀態
比較實用的東東,不然每次都自己去按numlock也很煩 字元終端下開啟numlock for tty in dev tty 1 6 dosetleds d num tty done 將上面的語句加入到系統啟動的指令碼中,比如 etc rc.d rc.local,加在結尾處就可以啦。x下開啟numlo...
C 判斷主機是否處於聯網狀態
直接讓本機訪問乙個 如果成功的話,就說明成功聯網,沒有訪問成功,則說明沒有聯網!include include pragma comment lib,ws2 32.lib define len 1024 接收資料的大小 using namespace std int main if lobyte w...
如何判斷程式處於I O等待
現象 程式啟動後正常執行,使用prstat p 看到內存在逐步增加。使用tail f 看到不停的有log輸出。突然在log列印一條sql被送往db server以後,程式似乎停下來了。沒有報錯,沒有core dump。診斷 程式pid 6208。要求mit做pfile,pstack,pflags。x...