-   Linux - Desktop (
-   -   Limit the number of times an application can be opened? (

w00dy101 03-26-2013 05:12 AM

Limit the number of times an application can be opened?
Hi Guys

I'm new here and fairly new to Linux as well :)

anyways... skipping to the point now...

I need to be able to limit a desktop users ability to open Chrome on the desktop!

We run a web application off of chrome, and what our users seem to be doing is opening the chrome application multiple times each time a new user mans the workstation.

This is creating issues for the software and I need to figure out a way to to prevent this from happening...

Any ideas? does something exists built in to limit the number of times programs can be run?

Would some sort of bash script solve the problem?

I would be keen to see what you guys think!

Thanks in advance

goumba 03-26-2013 05:43 AM

A rather simplistic script to ensure a program is not started if it is already running:




if [ ! -z "$PROCESSNAME" ] && [ ! -z "`ps -e | grep $PROCESSNAME`" ]
        # Replace the echo statement below with the desired command(s)
        echo $1 is not running

Beware this an be a little tricky. You must know the process name as it shows in the process list, not search for the binary name. For example: under Debian, Firefox is known as Iceweasel, but ps -e lists the process as "firefox-bin". Firefox's process name under Mint is simply "firefox"

Also note that if you only use parts of the process name, it will evaluate as true. Of course this can be taken care of with a little awkery.

Also in my original test script, I used a parameter passed to the script rather than $PROCESSNAME, which would make this more generic, and possibly more useful. Simply delete the line "PROCESSNAME=" and change $PROCESSNAME to $1 in the conditionals.

Habitual 03-26-2013 06:51 AM


if $(pgrep chro > 0) ; then pkill -9 chro ; else echo "False" ; fi
works here.

Have fun!

w00dy101 03-26-2013 08:30 AM

Thank you both!

I will explore these options and adapt them to my needs.

Habitual 03-26-2013 04:39 PM

No worries, I enjoyed the challenge. ;)

w00dy101 03-27-2013 07:56 AM

Thanks again

The script below solved the problem.




        if [ ! -z "$PROCESSNAME" ] && [ ! -z "`ps -e | grep $PROCESSNAME`" ]
                zenity  --warning --text="Chrome is already running (PID: $PROCID)"
                        if [ "$?" -eq "0" ]
                                zenity --question --text="Do you want to start a new session? This will close all existing Chrome Sessions"
                                        if [ "$?" -eq "0" ]
                                                kill -9 $PROCID &&
                                                google-chrome --Kiosk
        google-chrome --Kiosk

Created a custom menu launcher, used the Chrome Icon for it, now the users cant open tens of thousands of Chrome apps!

Habitual 03-27-2013 06:51 PM

Good Job. I love zenity/yad stuff. :)

All times are GMT -5. The time now is 08:07 AM.