Re: [gtkmm] prevent an application to running twice



> Hi everyone,
> 

Hello.

> Can somebody tell me how I can prevent an application to have multiple 
> instance.
> 

There are many ways to do this.  A common way is to have the application 
write to a pid file, and store its process id.  That way, when the application
starts, it can check the pid file.  If the file exists, and there is a process
with the correct name running under that pid, then the application bails.

In gtkmail, I use a named pipe to handle this:

    http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/gtkmail/gtkmail/src/main.cc?rev=1.11&content-type=text/vnd.viewcvs-markup

This allows me to not only detect running instances, but also to pop up
a compose window in response to a mailto url.  If you have trouble understanding
the code, reply off list and I'll explain.

cheers,
--
joey yandle                             ___====-_  _-====___
www.divisionbyzero.com            _--~~~#####//      \\#####~~~--_
/jwy/pubkey.asc                _-~##########// (    ) \\##########~-_
                              -############//  :\^^/:  \\############-
                            _~############//   (@::@)   \\############~_
                           ~#############((     \\//     ))#############~
                          -###############\\    (^^)    //###############-
                         -#################\\  / "" \  //#################-
                        -###################\\/      \//###################-
                       _#/:##########/\######(   /\   )######/\##########:\#_
                       :/ :#/\#/\#/\/  \#/\##\  :  :  /##/\#/  \/\#/\#/\#: \:
                       "  :/  V  V  "   V  \#\: :  : :/#/  V   "  V  V  \:  "
                          "   "  "      "   \ : :  : : /   "      "  "   "




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]