[Novalug] process intercommunication

Peter Larsen peter@peterlarsen.org
Thu Dec 29 20:11:07 EST 2016

On 12/29/2016 02:48 PM, Gary Knott via Novalug wrote:
> I'm running the Firefox browser, and I'm viewing my gmail
> page, and I'm "composing" an email to send to someone,
> and I click on the paperclip to "attach" a file (a pdf file
> generated from a .tex file actually), and the "file chooser"
> window pops-up, listing my top-level files, including
> the file I want to attach.
> Now I see it is out-of date, so I switch to a terminal
> window, and rebuild the pdf file I want to attach.
> The "file-chooser" window is automatically updated
> to show the date and size of the new file!
> Can anyone explain in some just-right detail how that
> trick is coded?   (How it might be coded is good, but
> how it really is coded is even better.)

This does vary from program to program, and has been one of the many
challenges we had to overcome with Linux - it's been hard to "agree" on
a proper tool to do inter process communication (IPC). DBUS has, at
least with Gnome, turned into the defacto inter communication protocol
between processes. Pretty much every event you can think of, goes over
DBUS - ie. finding a wireless network, getting a connection, opening a
file, launching a program and much much more. It usually does not have
mouse movement and keyboard messages - that's handled by the WM system
(usually).   A quick tutorial can be found here:

I ran "dbus-monitor" and got the following back on an action - I wonder
if you can tell what I did?

method call time=1483054956.640031 sender=:1.71 -> destination=:1.120
serial=201 path=/org/gtk/vfs/metadata; interface=org.gtk.vfs.Metadata;
   array of bytes "/home/plarsen/.local/share/gvfs-metadata/home" + \0
   array of bytes "/data/peterfolder" + \0
   array of bytes "/.local/share/Trash/files/peterfolder" + \0

Of course using DBUS requires both sides to use this protocol. But it
has the advantage that it's not just about files, but about user
actions. DBUS can be secured, allowing you only to see events that you
are allowed to follow.  For most of us, DBUS equals GUI stuff, and hence
belong to the session (login) you're using so we don't really have to
worry too much about security on the bus - it's already restricted to
our session. But you can subscribe to system level events, and again
only the events you're allowed to see (or raise) can be done.

It's actually quite a learning experience to just dump the message
queue. That's how I learned OS/2 and Windows C programming (same idea in
most GUI systems). It was quite an AHA moment when I saw all keyboard
and mouse events showing up, and a bit of reading about the hierarchy of
objects to understand which window was getting the events. DBUS is
easier because it's a subscriber based system. So you don't have to
think about which system is sending and which one is receiving - you
just broadcast. This is actually a great feature, as new systems can
start adding events to DBUS before there's actually client code
available to consume it.

But as I started with, there are (unfortunately?) lots of different
systems for process messaging. Someone already mentioned inotify which
is a kernel feature. Ie. you can state "tell me if something happens to
this socket, to this file, to this directory" etc. and when the OS
processes a command (different/same user - doesn't matter) you're
notified. But it's limited to read, open, close, write etc.  That said,
inotify is on all Linux distributions - so it's a reliable feature to
use.  For pure process to process communication, we all know it was one
of the components Linux (Unix) was created for. We have pipes, shared
memory and even older Unix implementations like System V IPC. Without
pipes we could not use our "|" in the shell. It's an easy way to send
data from one process to another, but as you know both processes must
agree to format and a lot more. DBUS is a lot more flexible and allows
more than just two processes to exchange data.

In your case, you're using the file manager like Nautilus from Gnome,
and hence you're most likely seeing the result of DBUS.

  Peter Larsen

More information about the Novalug mailing list