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

前端 未结 5 972
轮回少年
轮回少年 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:58

    In Windows you can use a program to do it because someone wrote a program that inserts a device driver into the running kernel to do it. By the way it can be dangerous to do this, because after you close a handle that a broken application was using, the application doesn't know that the handle was closed, and when the application opens some other unrelated object it doesn't know that the same handle might now refer to some other unrelated object. You really want to kill the broken application as soon as possible.

    In Linux surely you can use the same kind of technique. Write a program that inserts a module into the running kernel. Communicate with the module and tell it which handles to close. It will be equally dangerous to do so.

提交回复
热议问题