Hello,
I am trying to run some distributed jobs, and unfortunately what I am running may try to display some unimportant graphics which I dont care, and thus crash if no display is present. For this reason I dispatch a job which first creates an Xvfb virtual framebuffer, and outputs everything on this display.
My problem seems to be in detecting which display is free, so that I can start an Xvfb on that display. I have come up with a bash script, which get a start display of 10000, and checks if there is a lock file for this display. If not it increments the display or else starts an Xvfb there. There is the chance that because of a race condition another process may try the same display, so I check the exit status and if it is not 0, I increment the display to use and try again.
Unfortunately in some occasions (about 5-8% of the jobs), something may go wrong, and I get the following errors
Cannot establish any listening sockets - Make sure an X server isn't already run
ning
_XSERVTransSocketINETCreateListener: ...SocketCreateListener() failed
_XSERVTransMakeAllCOTSServerListeners: server already running
Fatal server error:
The script I use to detect the display is the following
Code:
set disp=10000
while ( 1 )
if ( -f "/tmp/.X$disp-lock" ) then
set disp=`echo $disp + 1 | bc`
else
Xvfb :$disp -screen 0 800x600x24 &
set xvfb_pid=`echo $!`
sleep 2
ps -p $xvfb_pid > /dev/null
if ( $? == 0 ) then
break
endif
endif
end
setenv DISPLAY :$disp
Any recommendations on my approach to detect free displays, or improvements on the script? Also any insight into what may be going wrong could help me work around the issue