Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-10

simpleipc

6 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Brad Campbell

G'day all,

I've been having a play with simpleipc.pp for trying to do cross-platform single instance detection.

Ordinarily it behaves perfectly, but I just noticed on Linux that it all comes crashing down if the server application crashes without removing the pipe.

I then have to manually remove the pipe to be able to start the server again.

Has anyone come up against this, or similar previously? I'm somewhat stumped as to how to go about solving this as I can't find a reliable way of detecting a listener on the end of the pipe.

I figure the best way to go about it is to move from pipes to unix sockets, but this then starts to get considerably more complex.

Brad

Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish.
Michael Van Canneyt
to Brad Campbell
Brad Campbell wrote 13 lines
G'day all, I've been having a play with simpleipc.pp for trying to do cross-platform single instance detection. Ordinarily it behaves perfectly, but I just noticed on Linux that it all comes crashing down if the server application crashes without removing the pipe. I then have to manually remove the pipe to be able to start the server again. Has anyone come up against this, or similar previously? I'm somewhat stumped as to how to go about solving this as I can't find a reliable way of detecting a listener on the end of the pipe.

You could write the server process id to a file, and detect whether the process is still alive.

Michael.

Brad Campbell
to Michael Van Canneyt
Michael Van Canneyt wrote 19 lines
On Thu, 16 Oct 2008, Brad Campbell wrote: > G'day all, > > I've been having a play with simpleipc.pp for trying to do cross-platform > single instance detection. > > Ordinarily it behaves perfectly, but I just noticed on Linux that it all comes > crashing down if the server application crashes without removing the pipe. > > I then have to manually remove the pipe to be able to start the server again. > > Has anyone come up against this, or similar previously? > I'm somewhat stumped as to how to go about solving this as I can't find a > reliable way of detecting a listener on the end of the pipe. You could write the server process id to a file, and detect whether the process is still alive.

What I ended up doing was creating a lockfile and having the server hold an exclusive lock on it. If the server starts and can get an exclusive lock then it know's it is the first process running, and to delete the ipc pipe if it hangs over from a crash. That is now working perfectly. (Except that simpleipc crashes on OSX when it tries to create the fifo, but that's another issue and not related to simpleipc).

I'm really quite impressed with simpleipc, it's made going cross platform very easy.

..actually, the whole freepascal/lazarus thing has made going cross platform very easy.

Regards,
Brad

Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish.
Luca Olivetti
to Brad Campbell

En/na Brad Campbell ha escrit:

Show quoted text 5 lines
What I ended up doing was creating a lockfile and having the server hold an exclusive lock on it. If the server starts and can get an exclusive lock then it know's it is the first process running, and to delete the ipc pipe if it hangs over from a crash.

Well, if you detected that's the first (and only) instance running, then you don't need the ipc server anymore, do you? (as long as it was used only to detect multiple invocations).
There's a component/unit named uniqueinstance/uniqueinstanceraw to do that, but since I had problems with it (the process starting more than once), I modified as you say to use a lockfile.
Somehow someone managed to start two copies of the same server, I still don't know how since I cannot reproduce it.

Bye

Luca
Brad Campbell
to Luca Olivetti
Luca Olivetti wrote 11 lines
En/na Brad Campbell ha escrit: > What I ended up doing was creating a lockfile and having the server > hold an exclusive lock on it. > If the server starts and can get an exclusive lock then it know's it > is the first process running, and to delete the ipc pipe if it hangs > over from a crash. Well, if you detected that's the first (and only) instance running, then you don't need the ipc server anymore, do you? (as long as it was used only to detect multiple invocations).

Which it's not. I also use it to open windows in the main instance from extra instances opened.

There's a component/unit named uniqueinstance/uniqueinstanceraw to do that, but since I had problems with it (the process starting more than once), I modified as you say to use a lockfile.

Which is precisely the component I am using, and precisely the problem I came up against. It works brilliantly until your main app crashes or is killed or, or, or.. then it just refuses to work until you manually clean up after it.

I also have problems with the component itself causing all sorts of segfaults if it aborts an application loading when it detects a previous instance. I worked around it, but it's still ugly in parts. If I manage to get it cleaned up and de-uglified I'll submit it back.

Somehow someone managed to start two copies of the same server, I still don't know how since I cannot reproduce it.

Since I made my modifications I've managed to avoid that nicely.

Brad

Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish.
Luiz Americo Pereira Camara
to Brad Campbell: I've been having a play with simpleipc.pp for trying to do cross-platform single instance…
Brad Campbell wrote 13 lines
G'day all, I've been having a play with simpleipc.pp for trying to do cross-platform single instance detection. Ordinarily it behaves perfectly, but I just noticed on Linux that it all comes crashing down if the server application crashes without removing the pipe. I then have to manually remove the pipe to be able to start the server again. Has anyone come up against this, or similar previously?

I already noticed that in the component i wrote to launch a single instance. No good solution found.

Luiz