Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Using Fedora
FedoraForum Search

Forgot Password? Join Us!

Using Fedora General support for current versions. Ask questions about Fedora and it's software that do not belong in any other forum.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 29th December 2007, 06:28 PM
senzmail Offline
Registered User
 
Join Date: Dec 2007
Posts: 10
How to ensure that only a SINGLE instance of a program runs at a given point of time?

How do I ensure that only a SINGLE instance of a program runs at a given point of time? For example I want to restrict that only one instance of Firefox runs. System should not allow another instance of Firefox if it is already running.

I also want to know if it is possible to set such a restriction by sysadmin, even if that particular software does not have such an option.
Reply With Quote
  #2  
Old 29th December 2007, 07:14 PM
daverj Offline
Registered User
 
Join Date: Jan 2006
Location: Denver, CO USA
Posts: 670
if an application itself does not include a way to do this you could always write a shell wrapper for it which would check for a running instance of the application and either launch or fail based on whether or not it found a running instance. To do this you could use the output of a 'ps -ef | grep ' command. obviously, You would need to know what the ps -ef output is for the application. To make it transparent, you could give the wrapper the same name as the executable and put it in /usr/local/bin and then put /usr/local/bin ahead of the other executable directories in your path; usually /usr/bin.

the following might get you started for a wrapper for firefox. Mind you, it is untested.

Code:
cygnus:davidj tmp > cat firefox
#!/bin/bash

ps -ef | grep -v grep | grep firefox > /dev/null
if [ "$?" -eq "1" ]; then
    /usr/bin/firefox &
else
    echo "firefox is already running"
fi
make the script executable, put it in /usr/local/bin.
Code:
cygnus:davidj tmp > cd /usr/local/bin
cygnus:davidj bin > sudo chmod a+x firefox
cygnus:davidj bin > ls -l firefox
-rwxr-xr-x 1 root root 157 2007-12-29 12:09 firefox
also make sure /usr/local/bin is before /usr/bin in your path: something like this:
Code:
cygnus:davidj tmp > echo $PATH
/bin:/usr/local/bin:/usr/bin:/usr/bin/X11:/usr/games/bin:/usr/X11R6
then when people launch firefox, the script in /usr/local/bin will be found before the executable in /usr/bin.

hope this helps,
davidj
Reply With Quote
  #3  
Old 29th December 2007, 08:20 PM
lazlow Offline
Registered User
 
Join Date: Aug 2005
Posts: 3,172
I think the more important question is, what are you trying to prevent form occurring by doing this? Running multiple instances for Firefox should not be an issue. If it is other programs at issue there are probably easier ways to prevent those issues.
Reply With Quote
Reply

Tags
ensure, instance, point, program, runs, single, time

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fedora Runs Very Slow After Some Time on Laptop vostok4 Using Fedora 5 4th March 2008 07:22 AM
Kopete crashes every single time on F8 spoilt Using Fedora 3 21st November 2007 12:05 PM
Any program to setup laptop as access point ?? wahaha Servers & Networking 0 10th March 2007 05:53 AM
My system freezes every single time raulherrerac Using Fedora 4 5th November 2005 09:26 PM


Current GMT-time: 02:54 (Friday, 24-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat