0

I would like to know how I could communicate with a running proccess, like Google Chrome does. If it already exist any instance of Google Chrome and you click in a external link (inside or outside browser), it opens a new tab.

Then, my questions is this communication occurs via sockets or something like that?

Thank you.

Alfredo Miranda
  • 108
  • 3
  • 8
  • http://www.tldp.org/LDP/tlk/ipc/ipc.html Just google for "Linux inter-process communication". – Max Malysh Nov 22 '14 at 23:48
  • Poor example. [Chrome runs as multiple processes](http://www.chromium.org/developers/design-documents/process-models). – Jerry Coffin Nov 22 '14 at 23:50
  • You could use pipes, etc, as @Shemhamforasch suggests, but usually GUI programs use the operating system's message bus. It's also common for platforms such as windows to have the 'launch as window' stuff builtin to the executor. I don't know the details, so not quite an answer. – tdelaney Nov 22 '14 at 23:51

2 Answers2

2

This really depends on your platform. GTK+ has GtkApplication (which builds on the GApplication class in GIO), Qt has QtSingleApplication, etc.

GApplication/GtkApplication will basically attempt to provide a D-Bus name (at least on Linux—I believe the mechanism is platform-dependent). If it is successful then you are the original application, if not then the application is already running and you can communicate with it via D-Bus.

nemequ
  • 16,623
  • 1
  • 43
  • 62
  • Actually, it's mine. I am programming a server, and I wanna do it able to change some settings using CLI. Then, I would like what would be best way to provide a interface to do that. – Alfredo Miranda Nov 23 '14 at 03:05
  • 1
    Then you should use whatever is convenient for you—if I were you I would probably just use whatever you are using for the server. If your server is an HTTPd, use HTTP. If it's ZeroMQ, use ZeroMQ, etc. If you are writing a network server just bind to a local port. If you are writing a D-Bus server use D-Bus, etc. There is no one true way to do this, so usually it is best to just leverage whatever existing infrastructure you already have in place. – nemequ Nov 23 '14 at 04:16
  • Thanks for your answer. When you told about local port, I've searched a little and found some stuffs about Unix Domain Sockets, which limits access just to local applications. – Alfredo Miranda Nov 24 '14 at 03:34
0

I think that combining this and this will solve your problem. Basically it makes possible to determine the pid of the running app (if there is any) and write to its stdin. You might want to signal to that process that there is new information to be processed (this should help for that).

Sockets, pipes, messages and shared memory are also nice alternatives, but at first glance this seemed to be the simplest.

Community
  • 1
  • 1
Ivaylo Petrov
  • 1,162
  • 9
  • 18