#! /bin/sh

#
# This script stops the VFB (Virtual Frame Buffer) under X that was
# started earlier is the session/job with the script startxvfb.sh.
#
# The variable environmental VFBWINDOW (set by startxvfb.sh) is used
# to determine which X process to kill.
#

#
# Make sure VFBWINDOW is set
#

if [ "X${VFBWINDOW}" = "X" ] ; then
  echo "Variable VFBWINDOW not set, can not terminate VFB"
  exit 99
fi

vfbproc=`ps x | grep X | grep vfb | grep " :$VFBWINDOW" | awk '{print $1}'`

echo "Killing process id $vfbproc"
kill $vfbproc
