One approach you might investigate if you're running under Win32 is
using mutexes - see Win32::Mutex. For instance, you might have one
mutex "MyProgram_IsRunning" that the first copy of the program would
grab and hang onto so long as it was running. Any copy of the program
that tries to run would attempt to grab that mutex with a wait of 0 and
if it didn't get it, it would know that another copy is running. The
second mutex could be called "MyProgram_BringToForeground". The main
copy of the program would watch for that mutex to be created - it would
periodically call Win32::Mutex->open("MyProgram_BringToForeground"). If
the call succeeds, it knows another program has created the mutex and
that it should make itself visible. The second program should wait for,
say, 2 seconds after creating the mutex before exiting. Not 100%
reliable, but probably good enough.
--Toby Ovod-Everett
-----Original Message-----
From: Octavian Rasnita [mailto:[EMAIL PROTECTED]
Sent: Tuesday, August 26, 2008 1:02 PM
To: [email protected]
Subject: IPC with WxPerl
Hi,
I have a program made with WxPerl which has the main window hidden and
which
can be shown using a tray icon.
I want to avoid opening that program twice, so after opening it, I want
to
test if the program is already opened, and if it is, I want to show its
hidden main window and if it is possible to set the focus to a certain
object.
I use File::Pid for testing if the program is already open, but I don't
know
how to switch to the process with a certain PID and I also don't know
how to
unhide a Wx frame from another process.
Can you give me some hints?
I think I would need to send a certain signal to that process using
kill()
and handle that signal using $SIG{} and do what I want then.
But I don't know what signal to use for things like these.
I have tried to trap signals like HUP and others, but they all kill the
running program.
Octavian