[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to communicate with a running external process with

From: Pascal J. Bourguignon
Subject: Re: How to communicate with a running external process with
Date: Tue, 23 Jul 2013 21:09:01 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

Thorsten Jolitz <> writes:

> OTOH, this topic has become quite interesting, and I'm still curious
> about my original question: how to use all these UNP mechanisms from
> Emacs Lisp when the other (Lisp) process is not a subprocess but already
> running (with a given PID). 

You started specifying only another "process" PID, but now you're saying
it's a "Lisp" process.  What does that mean?

If the PID is fixed, then the process is fixed, and therefore the
program of this process is fixed (even if you have the sources), the
process owner is fixed, etc, (unless some special cases where the
process is programmed to change those parameters, eg. a shell program or
an interpreter or indeed, a lisp implementation).

But you are not saying what the program of the other process is.  The
only thing you told us about it is that it has a HTTP server.  But by
what you're saying later, I've got the impression this HTTP server is
not actually running, is not actually listening to a TCP/IP port.  If it
is, why don't you tell us that you know what port it's listening to, and
how should you use emacs to connect to that port and perform the HTTP
requests you need?

It is trivial to obtain the map of listening ports and PID:

   sudo netstat -tnpl

(sudo is optional, it's to get the name of the program running in the
processes you don't own).

Now, you said lisp, but since you're building a history of imprecise
language, perhaps we should assume you mean Common Lisp?

There's a protocol that has been defined specifically to communicate
between an emacs and a Common Lisp process, with which a whole IDE has
been built in emacs, named slime (the backend, the library that
implements that protocol on the Common Lisp side is called swank (as is
called the protocol)).  With slime/swank you can connect a CL process
with an emacs, and from emacs, send CL expressions to evaluate to the CL
process and receive back results, and debug and develop CL programs.
But if you specifically meant that, you could easily read the manual of
slime which indicates how to create from emacs a new CL inferior process
running swank, and how to connect from emacs to an existing CL process
that runs a SWANK server (therefore that is listening to a specific
port, just like a HTTP server).

> Assume there are 2 otherLisp processes up and running and 2 Emacs
> processes, and you want to communicate from otherLisp with PID 5555 to
> Emacs with PID 6666.

As I told you, the only communication channels that use the PID to
identify the end point, is made of kill(2) and signal(2).

And as I told you, the receiver has better be ready to get the signal,
otherwise the default behavior for most signals is to kill the process.
Which is as good a reaction to a message as anything else.

So, for example, to send the USR1 message, I mean, the USR1 signal to
the process 5555 from emacs, you could do:

      (shell-command "kill -USR1 5555")

> But from an Emacs Lisp program, how would you establish pipe or socket
> communication to that one specific otherLisp process with PID 5555
> already running, and not under control of Emacs process with PID 6666?
> From all I heard, all you can do is send 'kill signals to that process. 

That's because you don't read the whole messages.  I've already
mentionned the emacs manual chapters you have to read to know that:

> In emacs, you can do that with "network processes":

__Pascal Bourguignon__           
A bad day in () is better than a good day in {}.  
You know you've been lisping too long when you see a recent picture of George 
Lucas and think "Wait, I thought John McCarthy was dead!" -- Dalek_Baldwin

reply via email to

[Prev in Thread] Current Thread [Next in Thread]