On 10/27/06, <b class="gmail_sendername">Darryl Palmer</b> <<a href="mailto:dpalmerjr@gmail.com">dpalmerjr@gmail.com</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<span class="q">On 10/27/06, <b class="gmail_sendername">David Trask</b> <<a href="mailto:dtrask@vcsvikings.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">dtrask@vcsvikings.org</a>> wrote:
<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
How could one write a script that could then become a launcher or menu<br>item that would poll the system to see if that program was already running<br>under the logged on user....if not....then launch the program....if<br>

yes....then abort.  This might make it easier to keep kids from going<br>"click happy" and opening multiple instances of a program.  Any ideas?<br></blockquote></div><br></span>You can use lockfile to do this, you can write something like
<br><br>#! /bin/bash<br><br>#Check to see if the lockfile exits<br>if lockfile -! -r 0 ~/.locks/lockfile-firefox; then<br>  echo "Unable to start firefox, lock file exists"<br>  exit 1<br>fi<br><br>firefox<br><br>

rm -f ~/.locks/lockfile-firefox<br></blockquote></div><br>While this implementation is nice, it does have the problem of the lockfile not being deleted when programs/apps crash.  Using ps would be better.  You can try something like
<br><br>#! /bin/bash<br><br>count=`ps | grep firefox | grep -v grep | wc -l | awk '{print $1}'`<br><br>if [ ! $count -eq "0" ]<br>then<br>  echo "Unable to start firefox, already running!"<br>  exit 1<br>
fi<br><br>firefox<br><br><br>Darryl<br>