如何从UNIX系统中的另一个进程关闭文件描述符 [英] How to close a file descriptor from another process in unix systems

查看:145
本文介绍了如何从UNIX系统中的另一个进程关闭文件描述符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以使用命令 lsof 获取所有正在运行的进程的文件描述符,但是我想做的是关闭其中一些描述符,而不将其放入该进程中.这可以在Windows上完成,因此您可以轻松地解除阻止某些应用程序.

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 inside that process. This can be done on Windows, so you can easily unblock some application.

有任何命令或功能吗?

推荐答案

在Windows中,您可以使用程序来执行此操作,因为有人编写了将设备驱动程序插入正在运行的内核中的程序来执行此操作.顺便说一句,这样做很危险,因为在您关闭了一个损坏的应用程序正在使用的句柄之后,该应用程序不知道该句柄已关闭,并且当该应用程序打开其他不相关的对象时,它也不知道现在相同的句柄可能会引用其他一些不相关的对象.您真的想尽快杀死损坏的应用程序.

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.

当然,在Linux中,您可以使用相同的技术.编写一个将模块插入正在运行的内核的程序.与模块通信,并告诉它要关闭的句柄.这样做同样危险.

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.

这篇关于如何从UNIX系统中的另一个进程关闭文件描述符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆