LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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-19-2004, 12:51 AM   #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, 04:52 AM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,990

Rep: Reputation: 67
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, 05:06 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
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 07:28 AM
Creating a linux cluster effect on a single linux machine? sidra Programming 0 10-28-2004 10:32 AM
Creating multiple users in Kmail with a single KDE user jonole Linux - Software 3 10-03-2004 01:36 AM
Printing is not possible for a single application using Samba and Cups SKH Linux - Software 0 01-29-2004 09:09 AM
Application to place single space with % between each line MasterC Linux - General 2 05-18-2003 02:16 PM


All times are GMT -5. The time now is 05:09 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration