1. Second instance
- Posted by DonCole Dec 04, 2015
- 1872 views
Hello everyone,
Thank you, Don Cole
2. Re: Second instance
- Posted by xecronix Dec 04, 2015
- 1848 views
Hello everyone,
Thank you, Don Cole
I've used 2 cross platform methods to do this in the past.
- Create a "lock.pid" file for your program
- Bind to a socket
In the first case, you might choose a location relative the your executable program and create a file. You could perhaps call the file "lock.pid". When you start your program you can create the file and when your program terminates, delete the file. If the file already exists when you start your program, then exit. There are some details I'm leaving out of this response. If you are interested in pursuing this, ask and fill in more details.
The second solution involves binding to a tcp/ip socket when your program starts. If you can't bind, assume it's because another instance of your program is running. This is a very easy and simple solution but it assumes that the host OS and/or firewall will not be too noisy about the binding. It also assumes that your predetermined port is usually/always available. Anyway, I've used this solution when it was not reasonable to use option 1. (And actually, it's easier IMO)
3. Re: Second instance
- Posted by ghaberek (admin) Dec 04, 2015
- 1805 views
If you're using Win32Lib then you can use setAppName() which will return non-zero if the application name is already in use (i.e. running).
if setAppName("Super Database") != 0 then warnErr("Application is already running") end if
Another option would be to search the list of active processes running on the system for a PID matching your own executable path.
Unfortunately, Euphoria currently lacks a cross-platform library for working with enumerating and controlling processes.
-Greg
4. Re: Second instance
- Posted by jimcbrown (admin) Dec 05, 2015
- 1787 views
Unfortunately, Euphoria currently lacks a cross-platform library for
controlling processes.
Not true. There is std/pipeio.e
Unfortunately, Euphoria currently lacks a cross-platform library for
enumerating
processes.
True. Though this is really easy on most flavors of nix - just search the files in /proc
5. Re: Second instance
- Posted by petelomax Dec 05, 2015
- 1759 views
See Edita\src\easinst.ew for a windows-only solution.
6. Re: Second instance
- Posted by jmduro Dec 05, 2015
- 1741 views
On Windows, I use Thomas Parslow's IPC library to do the job.
if not ipc_RegisterProcessName("<program name>") then puts(2, "<program name> is already running!\n") abort(1) end if
Jean-Marc
7. Re: Second instance
- Posted by ghaberek (admin) Dec 06, 2015
- 1723 views
Unfortunately, Euphoria currently lacks a cross-platform library for
controlling processes.
Not true. There is std/pipeio.e
The Pipe I/O library is only useful if you simply want to start a process and then forget about it.
Until we can determine the status of the process we started, I don't see it as terribly useful.
This is the type of loop we'll need if we want Pipe I/O to be useful:
atom p = process:exec( "my command" ) while process:is_running( p ) do sequence data = process:read( p ) -- do stuff end while
Unfortunately, Euphoria currently lacks a cross-platform library for
enumerating
processes.
True. Though this is really easy on most flavors of nix - just search the files in /proc
Yes, but it's inherently more complicated on Windows, as we know many things there are.
I suppose get_process_list() is just something that needs to go on the "wishlist" of features for Euphoria.
-Greg
8. Re: Second instance
- Posted by jimcbrown (admin) Dec 06, 2015
- 1688 views
Unfortunately, Euphoria currently lacks a cross-platform library for
controlling processes.
Not true. There is std/pipeio.e
The Pipe I/O library is only useful if you simply want to start a process and then forget about it.
Until we can determine the status of the process we started, I don't see it as terribly useful.
This is the type of loop we'll need if we want Pipe I/O to be useful:
atom p = process:exec( "my command" ) while process:is_running( p ) do sequence data = process:read( p ) -- do stuff end while
I was under the impression that one could do this today:
constant ESRCH = 3 object z = pipeio:create() object p = pipeio:exec( "my command", z ) while pipeio:get_errno() != ESRCH with entry do sequence data = pipeio:read( p[STDOUT] ) -- do stuff entry -- check if process is still alive and set errno appropriately if not pipeio:kill( p, 0 ) end while -- clean up by closing the pipes pipeio:kill( p )
Unfortunately, Euphoria currently lacks a cross-platform library for
enumerating
processes.
True. Though this is really easy on most flavors of nix - just search the files in /proc
Yes, but it's inherently more complicated on Windows, as we know many things there are.
I suppose get_process_list() is just something that needs to go on the "wishlist" of features for Euphoria.
-Greg
No argument from me on this. It's probably simple enough that if someone had a patch, we could sneak it into 4.1.0 and 4.0.6
9. Re: Second instance
- Posted by DonCole Jan 07, 2016
- 1611 views
Yes, I would like more details on method 1.
Thank you,
Don Cole
Hello everyone,
Thank you, Don Cole
I've used 2 cross platform methods to do this in the past.
- Create a "lock.pid" file for your program
- Bind to a socket
In the first case, you might choose a location relative the your executable program and create a file. You could perhaps call the file "lock.pid". When you start your program you can create the file and when your program terminates, delete the file. If the file already exists when you start your program, then exit. There are some details I'm leaving out of this response. If you are interested in pursuing this, ask and fill in more details.
The second solution involves binding to a tcp/ip socket when your program starts. If you can't bind, assume it's because another instance of your program is running. This is a very easy and simple solution but it assumes that the host OS and/or firewall will not be too noisy about the binding. It also assumes that your predetermined port is usually/always available. Anyway, I've used this solution when it was not reasonable to use option 1. (And actually, it's easier IMO)
10. Re: Second instance
- Posted by jmduro Jan 08, 2016
- 1596 views
I suppose get_process_list() is just something that needs to go on the "wishlist" of features for Euphoria.
Pete Stoner already wrote GetProcessList() for Windows in 2006. I used it, it works perfectly.
Jean-Marc