<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Dealing With Stupid Programs That Think They Need X</title>
	<atom:link href="http://www.hlynes.com/2008/09/09/dealing-with-stupid-programs-that-think-they-need-x/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hlynes.com/2008/09/09/dealing-with-stupid-programs-that-think-they-need-x/</link>
	<description></description>
	<lastBuildDate>Tue, 06 Sep 2011 19:08:21 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Huw Lynes</title>
		<link>http://www.hlynes.com/2008/09/09/dealing-with-stupid-programs-that-think-they-need-x/comment-page-1/#comment-55096</link>
		<dc:creator>Huw Lynes</dc:creator>
		<pubDate>Fri, 18 Sep 2009 17:38:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.hlynes.com/?p=98#comment-55096</guid>
		<description>Roman,

I like your solution better. I&#039;ll do some testing this weekend and update the post appropriately.

Thanks,
Huw</description>
		<content:encoded><![CDATA[<p>Roman,</p>
<p>I like your solution better. I&#8217;ll do some testing this weekend and update the post appropriately.</p>
<p>Thanks,<br />
Huw</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roman Zenka</title>
		<link>http://www.hlynes.com/2008/09/09/dealing-with-stupid-programs-that-think-they-need-x/comment-page-1/#comment-54258</link>
		<dc:creator>Roman Zenka</dc:creator>
		<pubDate>Wed, 19 Aug 2009 15:45:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.hlynes.com/?p=98#comment-54258</guid>
		<description>This script has a race condition - you are testing for the id of last running Xvfb to change. Somebody else can start another Xvfb after you test but before you start your Xvfb, therefore fooling your script.

Proposed fix:

create_xvfb () {
	DISPLAYNO=1
	while [ -z $xvfb_success ]
		do
		Xvfb :${DISPLAYNO} -screen 0 1024x1024x8 &gt;&amp; /dev/null &amp;
		XVFB_PID = $!
		sleep 1
			if ps --pid $XFVB_PID
                                then
                                echo &quot;Started XVFB on display $DISPLAYNO process $XVFB_PID&quot;
                                xvfb_success=1
                        else
                                echo &quot;Failed to run Xvfb on display $DISPLAYNO&quot; 
                                DISPLAYNO=$(($DISPLAYNO + 1))
                        fi
		fi
 		done
	export XVFB_PID
	export DISPLAY=:${DISPLAYNO}
	}

kill_xvfb () {
	kill $XVFB_PID
	}


It simplifies your code, you are not firing grep upon grep upon grep and I think it is more robust too. E.g. what if I had a user named &quot;Xvfb&quot; that would show up in ps?</description>
		<content:encoded><![CDATA[<p>This script has a race condition &#8211; you are testing for the id of last running Xvfb to change. Somebody else can start another Xvfb after you test but before you start your Xvfb, therefore fooling your script.</p>
<p>Proposed fix:</p>
<p>create_xvfb () {<br />
	DISPLAYNO=1<br />
	while [ -z $xvfb_success ]<br />
		do<br />
		Xvfb :${DISPLAYNO} -screen 0 1024x1024x8 &gt;&amp; /dev/null &amp;<br />
		XVFB_PID = $!<br />
		sleep 1<br />
			if ps &#8211;pid $XFVB_PID<br />
                                then<br />
                                echo &#8220;Started XVFB on display $DISPLAYNO process $XVFB_PID&#8221;<br />
                                xvfb_success=1<br />
                        else<br />
                                echo &#8220;Failed to run Xvfb on display $DISPLAYNO&#8221;<br />
                                DISPLAYNO=$(($DISPLAYNO + 1))<br />
                        fi<br />
		fi<br />
 		done<br />
	export XVFB_PID<br />
	export DISPLAY=:${DISPLAYNO}<br />
	}</p>
<p>kill_xvfb () {<br />
	kill $XVFB_PID<br />
	}</p>
<p>It simplifies your code, you are not firing grep upon grep upon grep and I think it is more robust too. E.g. what if I had a user named &#8220;Xvfb&#8221; that would show up in ps?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ceri Davies</title>
		<link>http://www.hlynes.com/2008/09/09/dealing-with-stupid-programs-that-think-they-need-x/comment-page-1/#comment-41057</link>
		<dc:creator>Ceri Davies</dc:creator>
		<pubDate>Wed, 10 Sep 2008 08:12:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.hlynes.com/?p=98#comment-41057</guid>
		<description>Process IDs will wrap, which is my main concern.  The awk pattern could be refined to filter out toothpicks, perhaps.

More importantly, I fed you a duff command line - -e overrides -U in most implementations, so you&#039;d probably need to drop it (I&#039;m pleased to comply with the rules that state when being a smartarse, it&#039;s compulsory to make at least one mistake).</description>
		<content:encoded><![CDATA[<p>Process IDs will wrap, which is my main concern.  The awk pattern could be refined to filter out toothpicks, perhaps.</p>
<p>More importantly, I fed you a duff command line &#8211; -e overrides -U in most implementations, so you&#8217;d probably need to drop it (I&#8217;m pleased to comply with the rules that state when being a smartarse, it&#8217;s compulsory to make at least one mistake).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: huw</title>
		<link>http://www.hlynes.com/2008/09/09/dealing-with-stupid-programs-that-think-they-need-x/comment-page-1/#comment-41040</link>
		<dc:creator>huw</dc:creator>
		<pubDate>Tue, 09 Sep 2008 22:13:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.hlynes.com/?p=98#comment-41040</guid>
		<description>ps on linux seems to sort by PID which given the way linux behaves seems to equate to latest process last. Hence the use of tail -n 1 which effectively gives us the PID of the last Xvfb to be spawned.

It didn&#039;t occur to me to use the -U flag of ps, I shall use it next time I need to grep $USERNAME it&#039;s clearly the better way. The awk trick doesn&#039;t work because the /Xvfb/ pattern matches the awk command and you end up with the PID of awk not Xvfb.</description>
		<content:encoded><![CDATA[<p>ps on linux seems to sort by PID which given the way linux behaves seems to equate to latest process last. Hence the use of tail -n 1 which effectively gives us the PID of the last Xvfb to be spawned.</p>
<p>It didn&#8217;t occur to me to use the -U flag of ps, I shall use it next time I need to grep $USERNAME it&#8217;s clearly the better way. The awk trick doesn&#8217;t work because the /Xvfb/ pattern matches the awk command and you end up with the PID of awk not Xvfb.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ceri Davies</title>
		<link>http://www.hlynes.com/2008/09/09/dealing-with-stupid-programs-that-think-they-need-x/comment-page-1/#comment-41036</link>
		<dc:creator>Ceri Davies</dc:creator>
		<pubDate>Tue, 09 Sep 2008 20:07:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.hlynes.com/?p=98#comment-41036</guid>
		<description>I wasn&#039;t aware of Xvfb, thanks Huw.

With regard to get_xvfb_pid, may I respectfully refer you to the -U option to ps(1) and awk pattern matches?
The function could be written with less overhead as:

get_xvfb_pid () { 
    XVFB_PID=`ps -efwwU $USERNAME &#124; awk &#039;/Xvfb/ {print $2}&#039;` 
    } 

The presence of tail in your pipeline looks wrong too, I think ps(1) sorts by controlling terminal then process id, neither of which are likely to be useful!</description>
		<content:encoded><![CDATA[<p>I wasn&#8217;t aware of Xvfb, thanks Huw.</p>
<p>With regard to get_xvfb_pid, may I respectfully refer you to the -U option to ps(1) and awk pattern matches?<br />
The function could be written with less overhead as:</p>
<p>get_xvfb_pid () {<br />
    XVFB_PID=`ps -efwwU $USERNAME | awk &#8216;/Xvfb/ {print $2}&#8217;`<br />
    } </p>
<p>The presence of tail in your pipeline looks wrong too, I think ps(1) sorts by controlling terminal then process id, neither of which are likely to be useful!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

