[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

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



On 10/27/06, Darryl Palmer <dpalmerjr gmail com> wrote:
On 10/27/06, David Trask <dtrask 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

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]