Prev | Current Page 314 | Next

Chris Tyler

"X Power Tools"


SCRIPTPID=$$
# Create an .Xauthority file if necessary
export XAUTHORITY=/home/$(whoami)/.Xauthority
if [ ! -f $XAUTHORITY ]
then
COOKIE=$(mcookie)
for ((D=0;D<100;D++))
do
14.13
14.13 Embedding an X Application in a Web Page 209
xauth -q add :$D . $COOKIE >/dev/null 2>&1
done
fi
# Run commands to set up the client in the background
(
# Wait for the Xvnc server to start (may not be required)
sleep 1
# Get the PID of the Xvnc server
XVNCPID=$(ps --ppid $SCRIPTPID|grep Xvnc|sed -n "s/^ *\([0-9]*\) .*$/\1/p")
# Get the display specification from the port number
# identified by netstat
DISPLAY=:$(/bin/netstat -ap 2>/dev/null|
sed -n "s=^[^:]*:60\([0-9][0-9]\).*LISTEN *${XVNCPID}/Xvnc.*$=\1=p" \
2>/dev/null|head -1|sed "s/^0//")
export DISPLAY
# Start the client - 'nice' lowers the priority because gnuchess
# tends to use the CPU heavily.
nice /usr/bin/xboard -geometry 346x435+0+0 -size small >/dev/null 2>&1
)&
# Start the VNC server - must be foreground for socket connection to work
/usr/bin/Xvnc -terminate -inetd -securitytypes none -depth 24 -geometry 348x437
# Tidy up - when the VNC server dies, kill all child processes
kill 0
sleep 3
kill -KILL 0
The key is the subshell code within the parenthesis: this code determines the Xvnc
PID by finding a child of the parent script with Xvnc as the program name, and then
using netstat to discover which TCP/IP port in the 6000??“6099 range has been opened
by that copy of Xvnc.


Pages:
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
biuro rachunkowe łódź Curriculum Vitae Wiadomości ze świata noclegi darłowo kreator www