0

From http://www.gnu.org/software/emacs/tour/

Emacs server

Some people like to keep only a single instance of Emacs open and edit all their files in there. Doing this has a few advantages:

You can kill/yank text between buffers in the same instance of Emacs. Emacs remembers argument histories (what commands you've used, what files you've opened, terms you've searched for, etc.), but only within each instance. If you have many customizations, starting new instances of Emacs is slow. Alas, when you type emacs in a shell to edit a file (or when $EDITOR is invoked by an external program), a new instance of Emacs is started. You can avoid this by using emacsclient, which instead opens a new frame connected to an existing instance of Emacs:

In your existing instance of Emacs, type M-x server-start. Or add (server-start) to your .emacs file to make it do that automatically at startup. To edit a file, type emacsclient -t FILENAME at a prompt. You can also change your $EDITOR to emacsclient -t if you're using programs that automatically invoke $EDITOR. (emacsclient -t opens a new frame on the terminal; alternatively, emacsclient -c opens a new X frame.) When you're done editing, type C-x C-c, which closes the frame.

  1. By a "instance" of Emacs, is it the same as an Emacs process, or a thread?
  2. Are different buffers (or windows, or frames) under the same Emacs window different threads of the emacs process? (I guess so) So do they communicate via shared memory?
  3. Are an Emacs server and its clients different processes, or the different threads of the same emacs process? (I guess not, but the quote same that a client is a frame of the server, and I guess a frame is just a thread of the same process)
  4. Generally, in the server-client model of an application, do the server and the clients run as different processes or threads? Is the communication between the server and clients done by shared memory or inter-process communication?
3
  1. In this context, an "instance of Emacs" refers to a single process.

  2. No, Emacs doesn't hold a thread for each open buffer. My current session has 129 open buffers (some 100 opened from files, the others being output buffers for certain subordinate processes - python, ruby, elixir interpreters, wanderlust folder and summary views, flycheck-mode syntax checkers, etc.) but only 3 active threads.

  3. The main Emacs process is the server, and each emacsclient runs in its own process, communicating with the server over UNIX domain sockets. When the server receives a connection request from a client, it opens the requested file in a new buffer in a new window in the server's frame. emacsclient has the sole function of sending the requested file to the server, and waiting for the server to return once you're done editing the file's buffer.

  4. Generally, clients and servers run as separate processes - there is no guarantee that client and server are on the same network, let alone the same machine. Some servers start a new thread to handle each incoming client connection (Apache can be built to do this, for example), but the client is a separate process possibly on another machine on the other side of the planet. And note that shared memory is a form of inter-process communication, as are, for example, UNIX domain sockets.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.