Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Title says it all. pgrep Xvfb only does half of the trick. It will not tell me the display number.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

I'm not sure what you're trying to accomplish, but you can check whether a X Display is available by running "x display info":

xdpyinfo -display :0 >/dev/null 2>&1 && echo "In use" || echo "Free"

Note: if you cannot access the display, it'll be reported as "Free" too. Another way is checking for the existence of /tmp/.X0-lock which contains the PID file of a X server.

Instead of displaying the command, a more reliable way would be checking for processes matching the binary:

pids=$(pidof /usr/bin/Xvfb)
if [ -n "$pids" ]; then
    processes="$(ps --format command --no-headers -ww --pid $pids)"
else
    echo "Not running"
fi

Source: https://github.com/Bumblebee-Project/Bumblebee/blob/master/install-files/common-functions#L112

share|improve this answer
    
xdpyinfo does the trick for me, thanks! Btw. I want to set the DISPLAY env variable based on Xvfb running on :0. –  Paweł Gościcki Sep 9 '11 at 8:29
    
    
So you're trying to get the display number used by Xvfb? Try using the ps command in my answer and use something like display=":${processes##*:}";display="${%% *}" to get the display number (assuming it's given with the command which is done for Xorg at least) –  Lekensteyn Sep 9 '11 at 11:51
    
I will have it running only on :0, so simple check for :0 is sufficient for my needs. Thanks again! –  Paweł Gościcki Sep 9 '11 at 17:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.