Job Control

Job control allows you to suspend or terminate jobs, or move jobs between the foreground and background. Job control commands are shown below. When used, %j indicates the job of interest.

Command

Description

CTRL-Z

Stop the foreground job

CTRL-C

Interrupt (terminate) foreground job

fg %j

Bring stopped or background job to foreground

bg %j

Move stopped job to background

kill %j

Kill (terminate) stopped or background job

stop %j

Stop background job

suspend

Suspend current shell (if non-login shell)

jobs

Display current job list

The job specifier %j has the following forms.

Specifier

Description

%

Current job (%+ and %% are synonyms for %)

%-

Previous job

%n

Job number n

%str

Job whose command line begins with str

%?str

Job whose command line contains str (if shell says No match, use %\?str)

The fg and bg commands have the shorthand forms listed below.

Specifier

Description

%j

Equivalent to fg %j

fg or %

Equivalent to fg %

%j&

Equivalent to bg %j

bg or %&

Equivalent to bg %

If the notify shell variable is set, the shell notifies you immediately when background jobs finish. Otherwise, notification occurs when the next prompt is printed.

Use stty to specify whether or not background jobs can write to your terminal, as shown below:

stty tostop       Force background jobs to stop when ready to write to terminal
stty -tostop      Allow background jobs to write to terminal

Get Using csh & tcsh now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.