Interprocess communication on multi-user machine

"Martin v. Löwis" martin at v.loewis.de
Thu Jun 29 16:26:08 EDT 2006


Michael Butscher wrote:
> I'm wanting a method for interprocess communication which is OS-
> independent (sockets would be the normal way to go), but which works if 
> multiple users use the machine at the same time so that one user has no 
> access to the communication of programs of another user.
> 
> Any hints?

The conventional solution is to use environment variables or well-known
temporary files for that. For example, the file could look like this

port=45413
cookie=9f563aeb2e5639cf574

Put the file into a per-user location, and hope that this "good enough"
to separate users. If access control is a must, you need
platform-specific code to deny read access to the file to anybody
but the user.

Alternatively, put the port number and the cookie into an environment
variable, e.g.

FOO_PORT=45413:9f563aeb2e5639cf574

This is technically better protected (practically, environment
variables might easier leak, e.g. when somebody types "env").
However, this works well only if you manage to set this up
for the entire user session, else you have to ask the user to
manually duplicate the environment variable in all shells
he cares about.

In case this isn't clear yet: the cookie should then be used
for authentication. Only trusted clients would know the right
cookie.

Regards,
Martin



More information about the Python-list mailing list