-->
Previous Table of Contents Next


Suspending emacs

You can suspend emacs —in fact, you can suspend almost any Linux application—by pressing <Ctrl-z>. This keystroke combination places the current application into the background and provides you with another shell prompt. The command to reactivate emacs depends on which shell you’re executing. You can type the command fg, which means to bring the background task to the foreground. If the shell you’re using doesn’t understand this command, type exit, which reactivates your emacs session with all your files and buffers still intact.

Switching Between emacs and Other Virtual Terminals

Linux provides the user with six virtual terminals—hence, you have six different sessions. While in emacs you can press <Ctrl-Alt-Fx >, where Fx is one of the keyboard function keys F1 through F6, to activate another terminal. If you haven’t already logged in to a session on that terminal, then you must do so, just like when you’re first booting Linux. You then have a completely active Linux session. To switch back to emacs, simply press <Ctrl-Alt-Fx > again. If you forget which session is running emacs, you can cycle through each of the virtual terminals by pressing <Ctrl-Alt> with each function key one by one.


See “Managing Users,” p. 107

You can also use the ps command to display all active processes, as shown in Listing 28.1. The output of the ps -guax command indicates which terminal each process is now executing.

Listing 28.1 Output from the ps Command


USER  PID %CPU %MEM SIZE  RSS TTY STAT START   TIME COMMAND

root    1  0.5  3.1   44  208  ?  S    20:48   0:00 init

root    6  0.0  1.8   24  124  ?  S    20:48   0:00 bdflush (daemon)

root    7  0.0  1.9   24  128  ?  S    20:48   0:00 update (bdflush)

root   23  0.0  2.9   56  200  ?  S    20:48   0:00 /usr/sbin/crond -l10

root   36  0.6  3.5   65  240  ?  S    20:48   0:00 /usr/sbin/syslogd

root   38  0.1  2.9   36  200  ?  S    20:48   0:00 /usr/sbin/klogd

root   40  0.3  3.2   68  216  ?  S    20:48   0:00 /usr/sbin/inetd

root   42  0.1  3.0   64  204  ?  S    20:48   0:00 /usr/sbin/lpd

root   47  0.1  6.0  259  404  ?  S    20:48   0:00 sendmail:accepting c

root   51  0.1  2.0   32  140  ?  S    20:48   0:00 selection -t ms

root   52  1.5  7.2  376  484 v01 S    20:48   0:01 -bash

root   53  0.3  3.4   88  232 v02 S    20:48   0:00 /sbin/getty tty2 3840

root   54  0.3  3.4   88  232 v03 S    20:48   0:00 /sbin/getty tty3 3840

root   55  0.2  3.4   88  232 v04 S    20:48   0:00 /sbin/getty tty4 3840

root   56  0.3  3.4   88  232 v05 S    20:48   0:00 /sbin/getty tty5 3840

root   57  0.3  3.4   88  232 v06 S    20:48   0:00 /sbin/getty tty6 3840

root   67  0.0  3.5   80  240 v01 R    20:49   0:00 ps -guax

You can then use that TTY value, in the range of v01 to v06, to pick the correct virtual terminal. For example, if the ps command indicates that emacs is now operating on tty v01 and tty v02, pressing <Alt-F1> or <Alt-F2> brings you back to the appropriate emacs session.

Accessing Linux Commands from Within emacs

Sometimes all you need to do is a quick check to see whether a file exists or to perform some other quick Linux command; you don’t need a full shell session to perform the action. In that case, you can execute shell commands from within emacs. To execute a shell within emacs, press <Ctrl-u><Esc><!>. You’re prompted to enter a shell command; enter the command and press <Return>. emacs passes the command to the Linux shell, which executes the command.

If you don’t press <Ctrl-u>, emacs places the output into a buffer/window called *Shell Command Output*. You learn more about windows later in this chapter, but basically windows allow you to see multiple buffers at once. emacs provides various commands to move around between windows and to delete windows (without deleting their corresponding buffers). To delete the output window, press <Ctrl-x><1>.


Previous Table of Contents Next