An idea! was...Re: [K12OSN] opening too many programs blanks screen K12LTSP

Darryl Palmer dpalmerjr at gmail.com
Fri Oct 27 20:03:06 UTC 2006


On 10/27/06, Darryl Palmer <dpalmerjr at gmail.com> wrote:
>
> On 10/27/06, David Trask <dtrask at vcsvikings.org> wrote:
> >
> > How could one write a script that could then become a launcher or menu
> > item that would poll the system to see if that program was already
> > running
> > under the logged on user....if not....then launch the program....if
> > yes....then abort.  This might make it easier to keep kids from going
> > "click happy" and opening multiple instances of a program.  Any ideas?
> >
>
> You can use lockfile to do this, you can write something like
>
> #! /bin/bash
>
> #Check to see if the lockfile exits
> if lockfile -! -r 0 ~/.locks/lockfile-firefox; then
>   echo "Unable to start firefox, lock file exists"
>   exit 1
> fi
>
> firefox
>
> rm -f ~/.locks/lockfile-firefox
>

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

#! /bin/bash

count=`ps | grep firefox | grep -v grep | wc -l | awk '{print $1}'`

if [ ! $count -eq "0" ]
then
  echo "Unable to start firefox, already running!"
  exit 1
fi

firefox


Darryl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/k12osn/attachments/20061027/d097be31/attachment.htm>


More information about the K12OSN mailing list