Job Control and the Shell

Many students do not seem to know about or make effective use of the job control capabilities of the shell. Most programs, once running, can be temporarily suspended by typing CTRL-Z. The shell maintains a list of all jobs it is currently managing, and you can get this list by typing ``jobs'' to the shell. Each job is listed along with a small integer job number which you use to identify the job to the shell. At any time, there is a notion of the current, or ``foreground'' job, which is indicated by a + in the jobs listing. Other jobs are called ``background'' jobs. A suspended foreground job can be restarted by typing ``fg''. A suspended background job can be restarted by typing ``fg %n'', where n is the job number. This causes the selected job to become the foreground job. The foreground job can be sent into the background by typing ``bg''. Jobs can continue to run in the background as long as they do not require terminal input or output. You can kill a job by typing ``kill %n'', where n is the job number.

A typical use of the job control facilities would be as follows: on logging in, start an editor such as Emacs or Jove, and read in the programs you are working on. When you wish to compile, suspend the editor, and issue compilation commands to the shell. Fix errors by reentering the editor and making changes, and then recompile. When the program compiles correctly, start a debugger such as GDB. Run the program from within the debugger and trace its execution to find bugs. If you need to view the source, suspend the debugger and reenter the editor. Continue debugging by suspending the editor and reentering the suspended debugger.

Using Emacs can help you avoid a lot of the above procedure, because it is capable of running a shell from within a buffer.