Departments & Programs

More

Controlling processes created by the shell for you



Last revision August 9, 2004

Table of Contents:

  1. Shell interpretation
  2. Editing command lines
  3. Stuck in a Unix login session?
  4. Program execution
  5. Simple commands
  6. Unix command syntax
  7. Controlling processes
  8. Your login environment

The methods described here work only with the C-shell found in Berkeley Unix (or its derivatives, such as tcsh), not with the Bourne shell in older System V Unix systems.

Interrupting the current foreground job

The current foreground job can be interrupted in various ways:

The interrupt key (normally CTRL-C) will send a signal to the foreground job; the normal response is for the process to terminate. However, some processes can capture this signal and then choose to do something else. Normally, they choose to cleanup (remove temporary files, etc.) and then terminate. This interrupt key is part of the terminal driver and works with any shell. You can even modify which key creates the interrupt using the stty program.

The CTRL-\ key sends a kill signal to the foreground job which, under normal circumstances, is guaranteed to terminate it. This signal cannot be captured by a process. However, this means the process cannot cleanup and is just summarily stopped. In some cases, a process can be stuck in a kernel wait state so this signal never reaches it. In that case, the process is unusable but cannot be killed. Your only option in such a case is to log out or break the network connection. This kill key is part of the terminal driver and works with any shell. You can even modify which key creates the kill signal using the stty program.

After a CTRL-\ is used to kill a program, you will often get a response Core dumped. The system created an image of the process as it was in memory and put that into a file name core in the current directory. These files are usually large and only useful if you plan to use the debugger on them. The initial user environment for new accounts on pangea prevents these from being written at all, using the C-shell command

limit coredumpsize 0

If you want to create core dumps for later analysis, you must issue a command to increase this limit from 0 to some larger number, for example

limit coredumpsize 8m

which allows core dumps of up to 8 Megabytes to be written to disk.

In the C-shell, the CTRL-Z key allows you to simply suspend execution of the foreground job, with the possibility of starting it again later or killing it. The job is just frozen in its current state and shunted off to the side.

You can press CTRL-Z at any time while a process is running in the foreground. The process will be immediately suspended, and the shell will print the message Stopped followed by a new shell prompt.

If you are already at the shell prompt, the CTRL-Z has no effect.

Suspending and restarting commands is very useful when you are in the middle of something (pine, for example), and you need to check something else, like the name of a file.

You can start and suspend several jobs (programs or commands). The shell keeps a stack of current jobs, whether suspended or running in the background.

<--Previous Overview Next-->

Comments or Questions?