I have some unit tests that need an X11 display so I plan to start Xvfb before running them, but to start Xvfb I will need a free display number to connect it to. My best guess
With full credit to this answer to the related question How high do X11 display numbers go?:
Recent X servers as of version 1.13 (Xvfb
, too) support the -displayfd
command line option: It will make the X server choose the display itself and write the display number back to the file descriptor
. It's a bit convoluted, but this would be a safe and race-condition-free way to ask Xvfb
to use any free display. A bash
example:
exec 6>display.log
Xvfb -displayfd 6
# The display number of the new Xvfb instance has been written to display.log
# Kill Xvfb
exec 6>&-