如何将 X11 窗口 ID 转换为进程 ID [英] How to convert a X11 window id to a process id

查看:39
本文介绍了如何将 X11 窗口 ID 转换为进程 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个小型应用程序,我需要根据进程的主窗口或子窗口的 X11 窗口 ID 找到进程的 PID.我看到了使用 _NET_WM_PID 进行此类转换的示例,但我不知道如何在不使用它的情况下进行转换.不使用 _NET_WM_PID 的原因是它没有在所有可用的窗口管理器中实现,我的应用程序需要在其中任何一个(或至少在大多数)上工作.有人可以帮助我,并就如何解决这个问题给我一些建议/方向吗?谢谢!

I'm working on a small application and I need to find the PID of a process given the X11 window ID of its main window or child windows. I saw examples for doing such a conversion using _NET_WM_PID, but I cannot figure out how to do it without using it. The reason for not using _NET_WM_PID is that it's not implemented in all the available window managers and my application needs to work on any one of them (or at least on most of them). Could somebody help me please and give me some suggestion/directions on how to solve this issue? Thank you!

推荐答案

通常,无法找出创建窗口的进程的 PID.可能是进程在机器上远程运行,也可能是机器甚至没有进程和 PID 的概念.

In general, it's not possible to find out the PID of a process that created a window. It may be that the process is running remotely on a machine, and it may be that the machine doesn't even have the notion of processes and PIDs.

如果您不相信最初创建客户端时有人存储了此信息,则您需要自己跟踪连接.找出客户端使用的连接类型(套接字等),找出该连接的终点,并找出哪个进程持有该终点.如何做到这一点(以及是否可能)高度依赖于操作系统.

If you don't trust anybody stored this information when the client was originally created, you will need to trace the connections yourself. Find out what kind of connection (socket etc) the client was using, find out where that connection ends, and find out which process holds that end. How to do that (and whether it is possible at all) is highly operating system dependent.

这篇关于如何将 X11 窗口 ID 转换为进程 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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