在某些 linux 程序中關閉奇怪的描述符 (Strange descriptor closing in some linux programs)


問題描述

在某些 linux 程序中關閉奇怪的描述符 (Strange descriptor closing in some linux programs)

在跟踪一些 linux 守護進程(例如 sendmail)時,我注意到其中一些會在開始時對多個描述符(通常從 3 到 255)調用 close()。這是故意做的還是做其他事情的某種副作用?


參考解法

方法 1:

It is usually done as part of making a process a daemon.

All file descriptors are closed so that the long‑running daemon does not unnecessarily hold any resources. For example, if a daemon were to inherit an open file and the daemon did not close it then the file could not be deleted (the storage for it would remain allocated until close) and the filesystem that the file is on could not be unmounted.

Daemonizing a process will also take a number of other actions, but those actions are beyond the scope of this question.

(by zbighcamh)

參考文件

  1. Strange descriptor closing in some linux programs (CC BY‑SA 3.0/4.0)

#file-descriptor #system-calls #linux






相關問題

在 Android 中持久化文件描述符 (Persisting File Descriptors in Android)

無法理解 select() 系統調用 (failure to understand select() system call)

文件描述符中實際存儲了多少信息? (How much information is actually stored in a file descriptor?)

為同一個文件描述符創建兩個文件是否定義明確? (Is creating two FILEs for the same file descriptor well-defined?)

Android文件描述符洩漏調試 (Android file descriptor leakage debuging)

C中的文件描述符分配 (File Descriptor Assignment in C)

在某些 linux 程序中關閉奇怪的描述符 (Strange descriptor closing in some linux programs)

c read() 導致錯誤的文件描述符錯誤 (c read() causing bad file descriptor error)

C中系統調用的文件句柄問題 (Filehandle issue with system call in C)

使用 copy_file_range 進行複制加速 (Copy acceleration with copy_file_range)

打開文件過多錯誤,但 99.5% 的 inode 是免費的 (Too many open files error but 99.5% inodes are free)

SIGPIPE 由於文件描述符和進程替換 (SIGPIPE due to file descriptors and process substitution)







留言討論