1 回答

TA貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超14個(gè)贊
在類 Unix 系統(tǒng)上,當(dāng)一個(gè)進(jìn)程打開一個(gè)文件時(shí),它會(huì)得到一個(gè)File descriptor指向進(jìn)程File table入口的文件,而進(jìn)程入口又是指磁盤上的inode 結(jié)構(gòu)。inode保存文件信息,包括data location.
目錄的內(nèi)容只是成對的 inode 編號(hào)和名稱。
如果你刪除一個(gè)文件,你只需inode從目錄中刪除一個(gè)鏈接,它inode仍然存在(只要沒有從某個(gè)地方指向它的鏈接,包括進(jìn)程)并且可以從/到讀取和寫入數(shù)據(jù)data location。
在 Windows 上,此代碼失敗,因?yàn)?Windows 不允許刪除打開的文件:
panic: remove test.txt: The process cannot access the file because it is being used by another process.
goroutine 1 [running]:
main.main()
D:/tmp/main.go:18 +0x1d1
exit status 2
- 1 回答
- 0 關(guān)注
- 136 瀏覽
添加回答
舉報(bào)