How to close a file descriptor from another process in unix systems

前端 未结 5 975
轮回少年
轮回少年 2021-01-30 21:56

You can use command lsof to get file descriptors for all running processes, but what I would like to do is to close some of those descriptors without being insi

5条回答
  •  一整个雨季
    2021-01-30 22:41

    There is much less need to do this on Unix than on Windows.

    On Windows, most programs tend to "lock" (actually deny sharing) the files they open, so they cannot be read/written/deleted by another program.

    On Unix, most of the time this does not happen. File locking on Unix is mostly advisory, and will only block other locking attempts, not normal read/write/delete operations. You can even remove the current directory of a process.

    About the only situation this comes up in normal usage in Unix is when trying to umount a filesystem (any reference at all to the mounted filesystem can block the umount).

提交回复
热议问题