Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-18-2004, 11:51 PM   #1
LQ Newbie
Registered: Nov 2003
Posts: 7

Rep: Reputation: 0
Creating Single Instance linux application

Hi all,

I want to create a single instance application on linux.
On windows we can create events or mutex to check the already running instance. How to make it on linux.

Old 11-19-2004, 03:52 AM   #2
Senior Member
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,990

Rep: Reputation: 69
By “single instance application”, I assume that you mean a program that can only be run once, and if run again a new instance will not start?

The traditional way to do this is to have the program write out its PID (process ID) to a lock file as soon as it starts up, unless the lockfile already exists.

If the lockfile already exists, then the process should read the PID from it instead. It should then check the file /proc/pid/cmdline, and extract the name of the running process. If it is the same as the name of the current process, then the lockfile should be deleted, and it should try again. Otherwise, it should exit.

There's probably a library that does this for you.

If the program could be run by a different user (and you want to prevent that), then you would normally put the lock file in /tmp, using the various routines to make a temporary file.

Hope that helps,

—Robert J. Lee
Old 11-19-2004, 04:06 AM   #3
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
Here's anopther thread about this.
It's about a lock file. It should be possible using a semaphore as well (see "man semctl").


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there an application for creating flash websites for linux (kde) Stevetgn Linux - Software 7 08-18-2005 06:28 AM
Creating a linux cluster effect on a single linux machine? sidra Programming 0 10-28-2004 09:32 AM
Creating multiple users in Kmail with a single KDE user jonole Linux - Software 3 10-03-2004 12:36 AM
Printing is not possible for a single application using Samba and Cups SKH Linux - Software 0 01-29-2004 08:09 AM
Application to place single space with % between each line MasterC Linux - General 2 05-18-2003 01:16 PM

All times are GMT -5. The time now is 12:02 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration