LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 11-18-2004, 11:51 PM   #1
praj_linux
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.

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

Rep: Reputation: 76
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
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Here's anopther thread about this.
http://www.linuxquestions.org/questi...hreadid=242069
It's about a lock file. It should be possible using a semaphore as well (see "man semctl").
 
  


Reply


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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:26 AM.

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