A way to get sender's PID ?

Thiago Macieira thiago at kde.org
Fri Nov 10 05:27:17 PST 2006

Thorsten Koch wrote:
>My short but important question is whether it is possible to get the PID
>from a sender and/or from a called server.

Yes, but the result can be unreliable.

>E.g. a client A calls server B and wants to execute method C. If the
>bus-daemon reads the message it should be possible to map an unique name
> (or connection name) to a PID. Is there a transparent and elegant way
> to do that or is it necessary to send everytime the PID within the
> message !?

Call GetConnectionUnixProcessID on the interface org.freedesktop.DBus on 
the D-Bus server. As the name says, this process is Unix-specific and not 
portable. You can cache the result, because it's not supposed to change.

However, it can change, since connections can be handed off to forked 
processes. This will happen quite often with KDE unique applications: the 
connection to the session bus is opened in the parent process, which soon 
later dies. The child process (with a new PID) inherits the open 
connection. The D-Bus server gets the PID wrong from then on.

Now, why does it matter which PID it is? Are you doing some external 
verification (i.e., you're receiving the PID to be compared to in another 

  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/dbus/attachments/20061110/d966549d/attachment-0001.pgp

More information about the dbus mailing list