Find a free X11 display number

前端 未结 5 1855
旧巷少年郎
旧巷少年郎 2021-02-19 23:51

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

5条回答
  •  深忆病人
    2021-02-20 00:26

    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>&-
    

提交回复
热议问题