[Gambas-user] Send a signal do a PID. Is it possible?
Benoit Minisini
gambas at ...1...
Thu Nov 17 00:12:03 CET 2005
On Wednesday 16 November 2005 23:50, Andre Saccomani wrote:
> i
> Is there anyway to send a signal to a linux PID? and if so, is there a way
> to catch these signals in a gambas application? So when I try to open a
> second instance of my program, it would check if is there one already
> running and then it could send a signal to the first instance before exit.
> This signal would cause my program (the first instance) do do a
> dlgMain.Show, or something like this. restoring it from tray.
> Hi,
> I would like to make a software that allows only one instance of it
> running at same time. So when someone try to open a second instance of the
> program, it would look if there is one already running, and if there is, I
> would like to make this second instance to exit.
> But before exit, I want it to send a message to the first instance. Is
> there anyway to do that? send a message to a program by having its PID?
> If possible, how can I send a message to a PID and how do I handle received
> messages?
> Thanks in advance,
> Andre
The problem cannot be solved entirely in Gambas at the moment.
But you first must understand that running a software "once" is more subtil on
Unix than on Windows.
Does "once" means:
- Only one process for this executable and for one user on the same system?
- Only one process for this executable and for one user on the same
display/desktop?
With X-Window, processes and displays can have the network between them, so
two processes from two different systems can run on the same desktop, and two
processes from the same system can run on two different desktops.
If your program is a GUI program, running a program "once" usually means: only
one process for this executable for this display/desktop.
KDE solved this problem with the DCOP protocol: the application registered to
the DCOP server, and if it was already registered, then it knows that another
was already started. It can then warn the first application instance with a
DCOP message.
It could be possible to implement this registration by storing an X11 property
in the display root window. Then, there will be the problem of sending the
first registered application that another one was launched. Something to
implement...
Last point, there is no way to catch signals in a Gambas application.
Regards,
--
Benoit Minisini
More information about the User
mailing list