473,394 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Re: Ensure only single application instance.

On Fri, Aug 29, 2008 at 6:51 AM, Heston James <he**********@live.co.ukwrote:
Good afternoon all.

I have an application/script which is launched by crontab on a regular
basis. I need an effective and accurate way to ensure that only one instance
of the script is running at any one time.

After a short look around the internet I found a couple of examples, such as
this one (http://code.activestate.com/recipes/474070/), however they both
seem to be focused on a windows based environment.

Can anyone offer their advice on how best to do this on a linux based
system?

I have been contemplating the idea of creating a pidfile which is destroyed
at the end of the script, will this suffice? is it fool proof? My only
concern with this is that if the script crashes or is stopped halfway
through processing for whatever reason, I'll be left with a dead pidfile on
the system and no successive runs will work.

I'm really interested to get your ideas guys, Thanks.

Heston

________________________________
Get Hotmail on your mobile from Vodafone Try it Now!
--
http://mail.python.org/mailman/listinfo/python-list
Why not look at the process list, and if you find two entries kill the
one that is just starting?
--
Stand Fast,
tjg. [Timothy Grant]
Aug 29 '08 #1
4 2831
On Fri, Aug 29, 2008 at 6:51 AM, Heston James <he**********@live.co.ukwrote:
Good afternoon all.

I have an application/script which is launched by crontab on a regular
basis. I need an effective and accurate way to ensure that only one instance
of the script is running at any one time.
You could create a named pipe in /tmp with a unique (static) name and
permissions that disallow any kind of read/write access. Then simply have
your script check for its existence when it starts. If it exists, then
another instance of your script is running, and just terminate. Make sure
your original instance removes the pipe when it exits.
Aug 29 '08 #2
In article <dP*******************@en-nntp-06.dc1.easynews.com>,
Uberman <bh*****@hotmail.comwrote:
>On Fri, Aug 29, 2008 at 6:51 AM, Heston James <he**********@live.co.ukwrote:
>Good afternoon all.

I have an application/script which is launched by crontab on a regular
basis. I need an effective and accurate way to ensure that only one instance
of the script is running at any one time.

You could create a named pipe in /tmp with a unique (static) name and
permissions that disallow any kind of read/write access. Then simply have
your script check for its existence when it starts. If it exists, then
another instance of your script is running, and just terminate. Make sure
your original instance removes the pipe when it exits.
I'll write an article on this subject this fall. The
essentials are:
A. There's no canonical answer; every apparent solution
has problems;
B. The suggestions offered you are certainly among the
popular ones;
C. My personal favorite is to open a (network) socket
server. For reasons I'll eventually explain, this
has particularly apt semantics under Unix.
Aug 29 '08 #3
On Aug 29, 11:25*pm, Uberman <bhoo...@hotmail.comwrote:
On Fri, Aug 29, 2008 at 6:51 AM, Heston James <heston_ja...@live.co.ukwrote:
Good afternoon all.
I have an application/script which is launched by crontab on a regular
basis. I need an effective and accurate way to ensure that only one instance
of the script is running at any one time.
The following is taken from the getmail FAQ -

------------------------------------------
If you need to prevent two instances of getmail from running
simultaneously, use any standard Unix method of providing a mutex for
this purpose. One example would be to run getmail under a program like
setlock (part of the daemontools package). Change your script or
crontab file to invoke getmail like this:

/path/to/setlock -n /path/to/lockfile /path/to/getmail [getmail
options]

There are other programs that provide functionality similar to
setlock.
------------------------------------------

HTH

Frank Millman
Aug 30 '08 #4
Cameron Laird wrote:
In article <dP*******************@en-nntp-06.dc1.easynews.com>,
Uberman <bh*****@hotmail.comwrote:
>On Fri, Aug 29, 2008 at 6:51 AM, Heston James <he**********@live.co.ukwrote:
>>Good afternoon all.

I have an application/script which is launched by crontab on a regular
basis. I need an effective and accurate way to ensure that only one instance
of the script is running at any one time.
You could create a named pipe in /tmp with a unique (static) name and
permissions that disallow any kind of read/write access. Then simply have
your script check for its existence when it starts. If it exists, then
another instance of your script is running, and just terminate. Make sure
your original instance removes the pipe when it exits.

I'll write an article on this subject this fall. The
essentials are:
A. There's no canonical answer; every apparent solution
has problems;
B. The suggestions offered you are certainly among the
popular ones;
C. My personal favorite is to open a (network) socket
server. For reasons I'll eventually explain, this
has particularly apt semantics under Unix.
Cameron,

I found this recipe (http://code.activestate.com/recipes/474070/) on
ActiveState's site that had a working version of a single instance class for
Windows that I've used quite successfully. Since I also work a lot Linux, I
wrote and donated this version (http://code.activestate.com/recipes/546512/) for
Linux that also seems to work well for me.

-Larry
Aug 30 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chris Anderson | last post by:
Could someone please tell me how I ensure only one instance of an application can execute concurrently?
2
by: Tom Kreyche | last post by:
I have an 3rd party app with VBA embedded, and I want to use it simply as a shell to call my C# application. This works fine using VBA's CreateObject("Shell.Application") and ShellExecute. ...
16
by: Elad | last post by:
Hi, I have an application that is made up of several executables. I need all these executables to use the same instance of an object. What is the best, most efficient way to approach this? ...
7
by: jsale | last post by:
I have made an ASP.NET web application that connects to SQL Server, reading and writing data using classes. I was recommended to use session objects to store the data per user, because each user...
6
by: Xenio | last post by:
Hi, I'd like to make sure that only one instance of my app is running per User Session. In addition this has to work with user rights and in a Windows 2k/2k3 and Citrix Terminalserver...
9
by: MrSpock | last post by:
1. Create a new Windows Application project. 2. Open the project properties and check "Make single instance application". 3. Build. 4. Go to the release folder and run the application. 5. Try to...
3
by: Mark Jerde | last post by:
VS 2005. When I google "CSharp single instance form" the returned pages usually use a Mutex or the VB.NET runtime library....
6
by: Jen | last post by:
I've implemented single-instance functionality in my .exe by using the mutex method. Works great. But when the .exe detects that it is not the first instance I want to bring the main window of...
1
by: =?Utf-8?B?UkY=?= | last post by:
Our client made a Vb.Net application which is configured to start as a Single instance application. Calling this application a second time with a specific command line argument will execute the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.