How do you prevent multiple instances of a program running?

Questions about applications and software
Forum rules
Before you post please read this

How do you prevent multiple instances of a program running?

Postby ldp on Tue Apr 24, 2012 11:45 am

Nor sure if this is a newbiw question, but how do you stop a program from kicking off multiple instances of itself?

Some explanation is needed: I'm a newbie and have been playing about with LinuxMint 12 LXDE and one of the many things I've been setting up (playing with) is conky. At first I was having trouble finding out how to get it to autostart, which I managed to do, but each time I log out and then back in again, another instance kicks off - or it appears to if you look at system monitor processs, although only one diaplays (one on top of the other?).

Is this simply that I've set up to autostart incorrectly? What I would like is to set it (or indeed any program) to run/start at the user level but prevent another instance of the application running at any one time.

I currently have a conky.desktop file in ~/.config/autostart/ - setting the application to start by adding and entry in autostart in /etc/xdg/lxsession/Mint-LXDE just appears does the same? What am I missing?

I'm thoroughly confused by the autostart process - or at least what works or appears to work!!!

If any of you bright lights could point me in the right direction.
ldp
 

Linux Mint is funded by ads and donations.
 

Re: How do you prevent multiple instances of a program runni

Postby DrHu on Tue Apr 24, 2012 2:01 pm

You are possibly starting conky from a terminal (tty # 1..6) via a script you have created ?, but if you were only using autostart and conky didn't already include itself in the system startup
    In Ubuntu's terms a service startup
    --consider that name just like a windows service that runs on boot
http://www.ubuntugeek.com/conky-a-light ... stems.html
http://www.junauza.com/2009/03/installs ... buntu.html

Then it would surely be an issue of being incorrectly configured for startup on boot

Ubuntu Conky, how it may bet started..
http://www.howtogeek.com/howto/ubuntu/h ... ter-login/
http://forum.intern0t.org/gnu-linux/406 ... conky.html
https://lusule.wordpress.com/2008/08/07/how-to-4/
    Save this script, for example, as conky.sh in a Scripts directory in your home folder. Set your autostart to this script, instead of directly to Conky. This script will wait a set time, before launching Conky. This should prevent any shadows
--conky configuration: one of the issues with Compiz ..
Last edited by DrHu on Tue Apr 24, 2012 2:06 pm, edited 1 time in total.
User avatar
DrHu
Level 15
Level 15
 
Posts: 5893
Joined: Wed Jun 17, 2009 8:20 pm

Re: How do you prevent multiple instances of a program runni

Postby AlbertP on Tue Apr 24, 2012 2:04 pm

@DrHu: Conky is not a system service, it runs within X / your user's session so needs to be loaded with the session or autostart and not by init.

Gnome based desktops have "Startup Applications" in the menu for this. Not sure how LXDE does it but /etc/xdg/lxsession seems the right place to configure such a thing for all users (if you want to configure things only for yourself, use the hidden folders/files in your home folder).
Registered Linux User #528502
Image
Feel free to correct me if I'm trying to write in Spanish, French or German.
AlbertP
Level 15
Level 15
 
Posts: 5834
Joined: Sun Jan 30, 2011 12:38 pm
Location: The Netherlands

Re: How do you prevent multiple instances of a program runni

Postby DrHu on Tue Apr 24, 2012 2:08 pm

AlbertP wrote:DrHu: Conky is not a system service, it runs within X / your user's session so needs to be loaded with the session or autostart and not by init.

OK, I stand so humbly corrected..
I did also note via various links, how to install, configure and add Conky to the autostart application folder..
    Perhaps that makes up for my sin!

OH, I didn't notice that he was using LXDE, so I did a quick search on that desktop, since it does work differently thahn Gnome (Mint ,main edition)
https://vuau.wordpress.com/2011/01/08/l ... top-files/
    Under almost every other major desktop environment, it’s a relatively simple task to set up applications to automatically start whenever you start the desktop. However, this is not necessarily so under LXDE. In fact, LXDE does not natively have an autostart directory, by default. Thanks to Neal Brooks, author of the PCLinuxOS-LXDE remaster, PCLinuxOS users of LXDE do have this feature already set up for them.

From that link site above, about openbox autostart functions..
http://openbox.org/wiki/Help:Autostart

He could match PCLINUX setup for an autostart directory (folder) and use its methods..
http://forum.vectorlinux.com/index.php?topic=6982.0
    Last post answer
    Code: Select all
    Put *.desktop files of those applications in ~/.config/autostart, and they will get executed when the session starts.
--You have to create your own desktop file, the contents of which are like launcher in Mint, the parameters needed to start the application from the desktop or a menu..

Finally I see this
Autostart Programs
nano /etc/xdg/lxsession/LXDE/autostart and add application to start at login “@conky” without quotes.
Code: Select all
 nano /etc/xdg/lxsession/LXDE/autostart and add application to start at login “@conky” without quotes.
User avatar
DrHu
Level 15
Level 15
 
Posts: 5893
Joined: Wed Jun 17, 2009 8:20 pm

Re: How do you prevent multiple instances of a program runni

Postby ldp on Tue Apr 24, 2012 6:04 pm

Thanks for the help but the real issue is not so much autostarting in itself - that's sorted - but the fact that when I log back in the session will launch another instance of the application.

The two ways I've got conky to autostart is via an '@conky' entry in /etc/xdg/lxsession/Mint-LXDE/autostart, and ~/.config/autostart/conky.desktop file.

Both kick off additional instances of conky if you log out and then back in again. Looking in System Monitor/Processes cleary shows an instance for each login (actually my conky diplsays the same thing).

Is there a parameter or CL option to launch an application preventing another instance running?
ldp
 

Re: How do you prevent multiple instances of a program runni

Postby DrHu on Tue Apr 24, 2012 7:36 pm

--I do notice he is using the pid number, so that seems to be the best method of being sure..

OK, just looking around, I don't actually use conky
--mainly because I don't need to look at the status of anything really, just run the applications I want..
https://lusule.wordpress.com/2008/08/07/how-to-4/
    Conky updates its information. total_run_times defines how often it will run before it shuts down (setting this to 0 will keep Conky running permanently).
--that might work..
    Conky pid parameters, comparing to the first running instancecould prevent another from starting..
    example..
    cmdline_to_pid string
    pid* --various
    if_running (process)
--there might be something in that

http://service.futurequest.net/index.ph ... le/View/23
--giving conky a max priorty or possibly there might be a way of assigning it to a window/worplace, and having it not start if there was an instance already running

Most of the time, if you logged out and thereby started a separate login session, I expect any programs that autostart to also autostart in the new login
--switching users might be different, or as above there may be some windows parameter available: I don't see any run_once variable in the list of conky options
    monitor
    monitor_number

You also might be able to specify a pid to force only running that pid number for conky..
if_running
--parameter/option for conky..
http://conky.sourceforge.net/variables.html
User avatar
DrHu
Level 15
Level 15
 
Posts: 5893
Joined: Wed Jun 17, 2009 8:20 pm

Re: How do you prevent multiple instances of a program runni

Postby ldp on Wed Apr 25, 2012 11:48 am

Thanks DrHu.

I will try to digest, understand, and follow the links all you've said!

My question is more from curiosity than from having a real problem. I was experimenting with conky - not sure whether I will keep it running in the future - but the general question is one around controlling multiple instances of programs, and in this case why the system prevents other apps from running multiple times, but not conky.

Are there any other applications that behave like this?

This is all the fun of learning how to use Linux.........
ldp
 

Linux Mint is funded by ads and donations.
 

Return to Software & Applications

Who is online

Users browsing this forum: No registered users and 11 guests