Path: utzoo!mnetor!uunet!mcvax!enea!zyx!aj From: aj@zyx.UUCP (Arndt Jonasson) Newsgroups: comp.emacs Subject: Re: Need Info: Server Mode Message-ID: <2401@zyx.UUCP> Date: 23 Mar 88 12:38:07 GMT References: <8803182102.AA07523@icst-cmr.arpa> <6227@bellcore.bellcore.com> Reply-To: aj@zyx.SE (Arndt Jonasson) Organization: ZYX Sweden AB, Stockolm, Sweden Lines: 52 In article <6227@bellcore.bellcore.com> perry@bellcore.com (Perry Metzger) writes: > [discussion about complexities with using Gnu Emacs in server mode] > >Oh, come on. This isn't a legitimate objection. You can easily >determine if there is an emacs running on the same tty or pty, so the >question of "do I send it a SIGCONT" is easy to handle. Similarly, the >client can pass its pid to the emacs in server mode and get a signal >back telling it to wake up. > >I think the benefits of having a scheme like this would be great. Most >people in the world still use terminals, not bitmapped displays. >Providing something that they can use conveniently is a big plus. On a perfectly vanilla Unix system (no sockets, streams, ptys, shared memory or messages), it is possible to implement a sort of job control, making it possible to switch back and forth between Gnu Emacs and almost any process running under it. Scenery: You start Emacs early in your login session. When you need an inferior shell, perform the 'suspend-emacs' command, which on Unix systems without job control will put you in an inferior shell. Then use that shell for whatever you need to do. When you need to run Emacs again, don't exit the shell, and don't start a new Emacs. Just do the command 'pop'. It will bring you back to the suspended Emacs. The 'suspend-emacs' command will bring you back to where you were when you typed 'pop'. This works not only for shells, but for all programs that allow the user to spawn programs (rn, mail, vi, Lisp, ...). This is immensely useful when all you have is a single screen. Even in a window system, I often use it instead of having to create a new window and leave the Emacs window unused. This scheme requires some rather small (but non-trivial) changes to the Gnu Emacs C code, no changes to the Emacs Lisp code, and the additional program 'pop'. Here is how it's done: Emacs keeps the pid of the inferior shell in a variable. Only if it is 0 will 'suspend-emacs' create a new shell. If it isn't 0, there is a temporary file /tmp/pop where is the pid of Emacs. In that file is the pid of the 'pop' process. To suspend, Emacs sends the 'pop' process a certain signal (SIGUSR1 in System V) and then goes to sleep. The 'pop' process simply exits upon receipt of the signal. [Perhaps this is telling it backwards..] When 'pop' is invoked, it creates the above-mentioned file with its own pid in it. The pid of Emacs is taken from the environment variable POPID, where Emacs will have put it when it created the inferior shell. 'pop' sends Emacs a signal and then does a 'pause', ignoring INT and QUIT signals. -- Arndt Jonasson, ZYX Sweden AB, Styrmansgatan 6, 114 54 Stockholm, Sweden email address: aj@zyx.SE or !mcvax!enea!zyx!aj