如何检查 gnome-terminal 中运行的程序
我想编写一个程序,打印当前聚焦的窗口名称,如果它是 gnome 终端,则打印当前 gnome 终端选项卡内正在运行的程序(例如 vim,如果 vim 会话正在运行)。
为了获取当前聚焦的窗口名称,我使用了:
<块引用>xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"
xprop -id 0x220ad5a | grep "WM_CLASS(STRING)"
如果当前窗口是 gnome-terminal,这将返回 'gnome-terminal'。
但是我怎样才能找到 gnome-terminal 内运行的程序(更准确地说:在当前 gnome-terminal 选项卡内)?我想过使用 dbus 但 gnome-terminal 似乎不支持它。
I want to write a program which prints the current focused window name and if it is a gnome-terminal, then prints out the running program inside the current gnome-terminal tab (for example vim, if a vim session is running).
To get the currently focused window name, I used:
xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"
xprop -id 0x220ad5a | grep "WM_CLASS(STRING)"
If the current window is a gnome-terminal, this will return 'gnome-terminal'.
But how can I find out the program running inside gnome-terminal (more precisely: inside the current gnome-terminal tab)? I thought about using dbus but gnome-terminal does not seem to support it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我需要解决同样的问题,经过一番调查后我发现
wmctrl 和 pstree 以相同的顺序打印进程。
免责声明:我不确定情况总是如此,但在我的情况下,我使用此方法打开“备忘单”进行手动审查,会立即检测到问题,因此没有问题。
这是一个演示脚本,运行时将输出与当前活动终端窗口相对应的 pstree 的正确行。为了调试,它将中间步骤打印到 ~/debug.txt
预期输出:
然后挑选所需的子项。
I needed to solve the same problem and after some investigation I discovered
that wmctrl and pstree prints processes in the same order.
DISCLAIMER: I'm not sure this is always the case but in my case where I use this method to open up a "cheatsheet" for manual review a problem with it would be detected immediately and so for had no problem.
Here is a demo-script that when run will output the correct row of the pstree that corresponds to the currently active terminal window. For debugging it prints intermediate steps into ~/debug.txt
Expected output:
Then pick out the desired child.
获取 gnome 终端 PID,并检查哪些进程将此数字作为 PPID。
我已经回答了几天前非常相似的问题,请参阅此链接了解详细信息。
Get the gnome terminal PID, and check which processes have this number as PPID.
I have answered a very similar question few days ago, see this link for details.
谢谢亚当!我快到了。使用 xprop 我可以获得 gnome 终端的 PID (6736)。但不幸的是,所有 gnome 终端窗口和选项卡都只有一个进程。使用两个打开的 gnome-terminal 窗口查看此 pstree 输出:
Is there a way to find out the bash pid of the current opening gnome-terminal tab?
Thanks Adam! I am almost there. With xprop I can get the PID of the gnome-terminal (6736). But unfortunately, there is only one process for all gnome-terminal windows and tabs. See this pstree output with two opened gnome-terminal windows:
Is there a way to find out the bash pid of the currently opened gnome-terminal tab?