linux查看正在运行的窗口,获取linux中打开的应用程序窗口的数量
我想检测由窗口管理器管理的特定应用程序的实例数量.目前,我有这个:
#!/bin/bash
# wmctrl required
pids=$(pidof $1)
IFS=' ' read -a pid_arr <<< "$pids"
matches=0
for pid in "${pid_arr[@]}"
do
matching_lines=$(wmctrl -l -p | egrep -c "^.+\b.+\b$pid\b")
matches=$((matches + $matching_lines))
done
echo $matches
假设我有三次打开firefox并且我将firefox作为参数传递,如果没有打开“子窗口”(例如首选项窗口),该函数将只返回正确的数字.否则,该函数也将计算这些窗口.
我想获得没有“子窗口”的窗口数量.
P.S.:做了一些改变.要计算没有对话窗口的窗口数,这是我目前的解决方案:
#!/bin/bash
pids=$(pidof $1)
IFS=' ' read -r -a pid_arr <<< "$pids"
matches=0
for pid in "${pid_arr[@]}"
do
ids=$(wmctrl -l -p | awk '$3=='$pid'{printf $1" "}')
IFS=' ' read -r -a id_arr <<< "$ids"
for id in "${id_arr[@]}"
do
if ! xprop -id "$id" |
egrep -q '(WM_TRANSIENT_FOR|_NET_WM_WINDOW_TYPE_DIALOG)'
then
((matches++))
fi
done
done
echo $matches
但是在firefox的情况下,脚本无法区分浏览器窗口及其首选项窗口,因为它们都不是对话框窗口.
上面的脚本对我来说已经足够了,因为我用它来弄清楚xfce4-appfinder有多少个窗口(没有对话窗口).对于xfce4-appfinder,脚本可以正常工作,因为它的首选项窗口很容易被识别为对话框窗口.在firefox中,甚至可以通过调用firefox -preferences独立打开首选项窗口.将这样的窗口识别为某种“子窗口”可能是不可能的.
以下是我对firefox的浏览器和首选项窗口的xprop和xwininfo的结果:
xwininfo(浏览器):
xwininfo: Window id: 0x1c0007f "bash - Get number of opened application windows in linux - Stack Overflow - Mozilla Firefox"
Root window id: 0xa1 (the root window) (has no name)
Parent window id: 0x1400048 (has no name)
1 child:
0x1c00080 (has no name): () 1x1+-1+-1 +1+37
Absolute upper-left X: 2
Absolute upper-left Y: 38
Relative upper-left X: 0
Relative upper-left Y: 14
Width: 956
Height: 511
Depth: 24
Visual: 0x20
Visual Class: TrueColor
Border width: 0
Class: InputOutput
Colormap: 0x22 (installed)
Bit Gravity State: NorthWestGravity
Window Gravity State: NorthWestGravity
Backing Store State: NotUseful
Save Under State: no
Map State: IsViewable
Override Redirect State: no
Corners: +2+38 -962+38 -962-531 +2-531
-geometry 956x511+0+22
Bit gravity: NorthWestGravity
Window gravity: NorthWestGravity
Backing-store hint: NotUseful
Backing-planes to be preserved: 0xffffffff
Backing pixel: 0
Save-unders: No
Someone wants these events:
KeyPress
KeyRelease
ButtonPress
ButtonRelease
EnterWindow
LeaveWindow
PointerMotion
Exposure
VisibilityChange
StructureNotify
FocusChange
PropertyChange
Do not propagate these events:
Override redirection?: No
Window manager hints:
Client accepts input or input focus: Yes
Initial state is Normal State
Displayed on desktop 0
Window type:
Normal
Process id: 792 on host T530
Normal window size hints:
Program supplied minimum size: 300 by 71
Program supplied maximum size: 32767 by 32767
Program supplied window gravity: NorthWestGravity
No zoom window size hints defined
No window shape defined
No border shape defined
xwininfo(首选项):
xwininfo: Window id: 0x1c046ef "Firefox Preferences"
Root window id: 0xa1 (the root window) (has no name)
Parent window id: 0x1400060 (has no name)
1 child:
0x1c046f0 (has no name): () 1x1+-1+-1 +961+37
Absolute upper-left X: 962
Absolute upper-left Y: 38
Relative upper-left X: 0
Relative upper-left Y: 14
Width: 956
Height: 1040
Depth: 24
Visual: 0x20
Visual Class: TrueColor
Border width: 0
Class: InputOutput
Colormap: 0x22 (installed)
Bit Gravity State: NorthWestGravity
Window Gravity State: NorthWestGravity
Backing Store State: NotUseful
Save Under State: no0x1c00001
Map State: IsViewable
Override Redirect State: no
Corners: +962+38 -2+38 -2-2 +962-2
-geometry 956x1040-0-0
Bit gravity: NorthWestGravity
Window gravity: NorthWestGravity
Backing-store hint: NotUseful
Backing-planes to be preserved: 0xffffffff
Backing pixel: 0
Save-unders: No
Someone wants these events:
KeyPress
KeyRelease
ButtonPress
ButtonRelease
EnterWindow
LeaveWindow
PointerMotion
Exposure
VisibilityChange
StructureNotify
FocusChange
PropertyChange
Do not propagate these events:
Override redirection?: No
Window manager hints:
Client accepts input or input focus: Yes
Initial state is Normal State
Displayed on desktop 0
Window type:
Normal
Process id: 792 on host T530
Normal window size hints:
Program supplied location: 0, 0
Program supplied minimum size: 604 by 594
Program supplied maximum size: 32767 by 32767
Program supplied window gravity: NorthWestGravity
No zoom window size hints defined
No window shape defined
No border shape defined
xprop(浏览器):
_DESKTOP(CARDINAL) = 0
WM_STATE(WM_STATE):
window state: Normal
icon window: 0x0
WM_HINTS(WM_HINTS):
Client accepts input or input focus: True
Initial state is Normal State.
bitmap id # to use for icon: 0x1c00082
bitmap id # of mask for icon: 0x1c00083
window id # of group leader: 0x1c00001
_NET_STARTUP_ID(UTF8_STRING) = "xfce4-appfinder/|usr|lib|firefox|firefox/756-0-T530_TIME21351"
WM_WINDOW_ROLE(STRING) = "browser"
XdndAware(ATOM) = BITMAP
_MOTIF_DRAG_RECEIVER_INFO(_MOTIF_DRAG_RECEIVER_INFO) = 0x6c, 0x0, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0
_NET_WM_SYNC_REQUEST_COUNTER(CARDINAL) = 29360257
_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_NORMAL
_NET_WM_USER_TIME(CARDINAL) = 1758669
_NET_WM_USER_TIME_WINDOW(WINDOW): window id # 0x1c00080
WM_CLIENT_LEADER(WINDOW): window id # 0x1c00001
_NET_WM_PID(CARDINAL) = 792
WM_LOCALE_NAME(STRING) = "en_US.UTF-8"
WM_CLIENT_MACHINE(STRING) = "T530"
WM_NORMAL_HINTS(WM_SIZE_HINTS):
program specified minimum size: 300 by 71
program specified maximum size: 32767 by 32767
window gravity: NorthWest
WM_PROTOCOLS(ATOM): protocols WM_DELETE_WINDOW, WM_TAKE_FOCUS, _NET_WM_PING, _NET_WM_SYNC_REQUEST
WM_CLASS(STRING) = "Navigator", "Firefox"
WM_ICON_NAME(STRING) = "bash - Get number of opened application windows in linux - Stack Overflow - Mozilla Firefox"
_NET_WM_ICON_NAME(UTF8_STRING) = "bash - Get number of opened application windows in linux - Stack Overflow - Mozilla Firefox"
WM_NAME(STRING) = "bash - Get number of opened application windows in linux - Stack Overflow - Mozilla Firefox"
_NET_WM_NAME(UTF8_STRING) = "bash - Get number of opened application windows in linux - Stack Overflow - Mozilla Firefox"
xprop(首选项)
_NET_WM_DESKTOP(CARDINAL) = 0
WM_STATE(WM_STATE):
window state: Normal
icon window: 0x0
WM_HINTS(WM_HINTS):
Client accepts input or input focus: True
Initial state is Normal State.
bitmap id # to use for icon: 0x1c046f2
bitmap id # of mask for icon: 0x1c046f3
window id # of group leader: 0x1c00001
WM_WINDOW_ROLE(STRING) = "Preferences"
XdndAware(ATOM) = BITMAP
_MOTIF_DRAG_RECEIVER_INFO(_MOTIF_DRAG_RECEIVER_INFO) = 0x6c, 0x0, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0
_NET_WM_SYNC_REQUEST_COUNTER(CARDINAL) = 29378289
_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_NORMAL
_NET_WM_USER_TIME(CARDINAL) = 1456410
_NET_WM_USER_TIME_WINDOW(WINDOW): window id # 0x1c046f0
WM_CLIENT_LEADER(WINDOW): window id # 0x1c00001
_NET_WM_PID(CARDINAL) = 792
WM_LOCALE_NAME(STRING) = "en_US.UTF-8"
WM_CLIENT_MACHINE(STRING) = "T530"
WM_NORMAL_HINTS(WM_SIZE_HINTS):
program specified location: 0, 0
program specified minimum size: 604 by 594
program specified maximum size: 32767 by 32767
window gravity: NorthWest
WM_PROTOCOLS(ATOM): protocols WM_DELETE_WINDOW, WM_TAKE_FOCUS, _NET_WM_PING, _NET_WM_SYNC_REQUEST
WM_CLASS(STRING) = "Browser", "Firefox"
WM_ICON_NAME(STRING) = "Firefox Preferences"
_NET_WM_ICON_NAME(UTF8_STRING) = "Firefox Preferences"
WM_NAME(STRING) = "Firefox Preferences"
_NET_WM_NAME(UTF8_STRING) = "Firefox Preferences"
linux查看正在运行的窗口,获取linux中打开的应用程序窗口的数量相关推荐
- linux查看进程运行命令行参数,linux查看进程运行命令
Linux系统下想要查看运行中的进程,那我们该使用那个命令呢?下面由学习啦小编为大家整理了linux查看进程运行的命令的相关知识,希望对大家有帮助. 1.linux查看进程命令详解 ps命令查找与进程 ...
- 查看当前系统运行的服务器,linux 查看当前运行的所有服务器
linux 查看当前运行的所有服务器 内容精选 换一换 内存是GaussDB(DWS)运行的一个关键资源,如果能够有效利用,可以提升业务查询性能.而资源池是GaussDB(DWS)管理系统资源的集合, ...
- linux查看端口被占用且释放,Linux查看端口占用情况,并强制释放占用的端口
1.查找被占用的端口 netstat -tln netstat -tln | grep 8080 netstat -tln 查看端口使用情况,而netstat -tln | grep 8080则是只查 ...
- C语言中打开一个应用程序可以调用或运行命令
C语言中打开一个应用程序可以调用或运行命令system(),也可以调用操作系统的API函数,比如Windows系统可以调用CreateProcess().ShellExecuteEx()等函数来打开一 ...
- Linux查看进程运行的完整路径方法
通过ps及top命令查看进程信息时,只能查到相对路径,查不到的进程的详细信息,如绝对路径等.这时,我们需要通过以下的方法来查看进程的详细信息: Linux在启动一个进程时,系统会在/proc下创建一个 ...
- Linux查看、运行和杀死java进程
操作 命令 查看java进程 ps -ef | grep java 不挂断运行命令 nohup java -jar 文件名.jar & 停止特定java进程命令 kill 进程序号 停止所有j ...
- linux从光盘中安装php,Linux_Vfloppy通过CD光盘安装Linux到硬盘运行,光盘版的linux系统,可以证我 - phpStudy...
Vfloppy通过CD光盘安装Linux到硬盘运行 光盘版的linux系统,可以证我们无需安装,就可直接运行,避免了,不懂安装,安装失败等,如复制在硬盘运行,更是方便,速度比在光盘上运行快得多,而且每 ...
- linux 查看内存用量_正确计算linux系统内存使用率
图中的例子很典型,就是:多数的linux系统在free命令后会发现free(剩余)的内存很少,而自己又没有开过多的程序或服务. 对于上述的情况,正确的解释是: linux的内存管理机制与windows ...
- linux VCS+verdi运行UVM实战(第二章)中的例子
目录 前言 介绍 建立工程 运行代码 查看波形 总结 前言 用VCS+verdi运行了下UVM实战中的例子(第二章). 介绍 在某宝上花了几十块,买了个虚拟机(已经安装好VCS+verdi).直接用U ...
最新文章
- 第二章(jQuery选择器)
- 1.0 添加WEB API项目并按注释生成文档(多项目结构)
- 【图像处理】——图像的二值化操作及阈值化操作(固定阈值法(全局阈值法——大津法OTSU和三角法TRIANGLE)和自适应阈值法(局部阈值法——均值和高斯法))
- SQL语言基础:SQL授权相关知识笔记​
- [读书笔记] 敏捷软件开发:原则、模式与实践
- HP-JavaUtil: xls 操作类
- http post请求 参数放在路径后面 java_【思唯网络学院】网络基本概念之HTTP协议...
- POJ-3267 The Cow Lexicon---删除字符匹配单词
- 批量获取百度网盘文件目录
- Comparing the Effects of DNS, DoT, and DoH
- Linux命令行操作串口收发数据(stty命令)
- Linux下shell脚本的4中执行方式
- 不知道视频画面大小裁剪怎么操作?1分钟教你学会裁剪大小
- Linux shell:脚本编写快速入门
- canvas 将折线转换成曲线
- JavaFX图片浏览并实现缩放
- 【转】Awesome Python中文版来啦!
- UPS不间断电源工作原理简述
- 使用html编写SVG圆图形,CSS vs. SVG:任意图形UI组件
- 交换冗余之网关冗余HSRP、VRRP、GLBP