5

When I execute an application with xvfb-run, I can either explicitly specify an X11 server number (i.e. 44), or I can use --auto-servernum, which will assign one for me.

If I use --auto-servernum, how do I know what number it picked?

I'm trying to use this in a script, so if xvfb-run could output that somewhere so that I can use subsequent commands on the right X11 server, that'd be helpful.

Brad
  • 6,629

2 Answers2

6

It is put into the DISPLAY environment variable. You can see this by running

printenv DISPLAY
xvfb-run printenv DISPLAY
printenv DISPLAY

The first and last will show your regular display, the middle one will show the xvfb one.

2

From the command used to run actual Xvfb

ps -eo args|grep Xvfb

which outputs sth like

Xvfb :99 -ac -fbdir /tmp/ -nolisten tcp
Xvfb :100 -screen 0 640x480x24 -nolisten tcp
grep Xvfb

From the auth file

xvfb-run uses an X authority file you can read the info from. Assuming it lives in /tmp, get the display number withxauth list on the file:

xauth -f $(ls -rt1 /tmp|grep xvfb-run|tail -1)/Xauthority* list

which outputs something like

hostname/unix:99  MIT-MAGIC-COOKIE-1  4514215c67d5b0b8d389792ca7c4b9cc

where :99 is the display number. The file structure with random filenames looks like

/tmp
└── xvfb-run.I9aLaw
    └── Xauthority.CPACw7

The behaviour is described in the man page:

OUTPUT FILES

Unless the -f or --auth-file options are specified, a temporary directory and file within it are created (and deleted) to store the X authority cookies used by the Xvfb server and client(s) run under it.

cachius
  • 859