There is no good way. The least bad way I am aware of is to inspect the contents of /tmp/.X11-unix
; this will contain Unix domain sockets named X0
for :0
, X1
for :1
, and so on. If you want a TCP socket instead, attempt to connect to port 6000 and up until you get ECONNREFUSED
. Beware that both of these approaches have inherent race conditions which are AFAIK unfixable.
How do I get the first unused display in X? [closed]
سؤال
How do I get the first unused X display in either Python (Don't think there's a way) or {,ba,z}sh? It could return <number>
, :<number>
, or $(hostname):<number>
).
For example:
- X session at :0, 1 returned.
- X session at :0, VNC at :1, 2 returned.
- X session at :0, QEMU at :2, 1 returned.
المحلول
لا تنتمي إلى StackOverflow