[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Commands Reference, Volume 3


jobs Command

Purpose

Displays status of jobs in the current session.

Syntax

jobs-l | -n | -p ] [ JobID ... ]

Description

The jobs command displays the status of jobs started in the current shell environment. If no specific job is specified with the JobID parameter, status information for all active jobs is displayed. If a job termination is reported, the shell removes that job's process ID from the list of those known by the current shell environment.

The /usr/bin/jobs command does not work when operating in its own command execution environment, because that environment does not have applicable jobs to manipulate. For this reason, the jobs command is implemented as a Korn shell or POSIX shell regular built-in command.

If the -p flag is specified, output consists of one line for each process ID. If no flags are specified, standard output is a series of lines with the following fields:

job-number Indicates the process group number to use with the wait, fg, bg, and kill commands. When used with these commands, prefix the job number with a % (percent sign).
current A + (plus sign) identifies the job that will be used as a default for the fg or bg commands. This job ID can also be specified using the %+ (percent sign, plus) or %% (double percent sign).

A - (minus sign) identifies the job that becomes the default if the current default job exits. This job ID can also be specified using %- (percent sign, minus).

For other jobs, the current field is a space character. Only one job can be identified with a +, and only one job can be identified with a -. If there is a single suspended job, that will be the current job. If there are at least two suspended jobs, then the previous job is also suspended.

state Displays one of the following values (in the POSIX locale):

Running
Indicates that the job has not been suspended by a signal and has not exited.

Done
Indicates that the job completed and returned exit status 0.

Done (code)
Indicates that the job completed normally and that it exited with the specified non-zero exit status code. This code is expressed as a decimal number.

Stopped
Indicates that the job was suspended.

Stopped (SIGTSTP)
Indicates that the SIGTSTP signal suspended the job.

Stopped (SIGSTOP)
Indicates that the SIGSTOP signal suspended the job.

Stopped (SIGTTIN)
Indicates that the SIGTTIN signal suspended the job.

Stopped (SIGTTOU)
Indicates that the SIGTTOU signal suspended the job.
command The associated command that was given to the shell.

If the -l flag is specified, a field containing the process group ID is inserted before the state field. Also, more processes in a process group may be output on separate lines, using only the job-number and command fields.

Flags


-l (lowercase L) Provides more information about each job listed. This information includes the job number, current job, process group ID, state, and the command that initiated the job.
-n Displays only jobs that have stopped or exited since last notified.
-p Displays the process IDs for the process group leaders for the selected jobs.

By default the jobs command displays the status of all stopped jobs, all running background jobs, and all jobs whose status has changed but not been reported by the shell.

Exit Status

The following exit values are returned:

0 Successful completion.
>0 An error occurred.

Examples

  1. To display the status of jobs in the current environment, enter:

    jobs -l
    

    The screen displays a report similar to the following output:

    +[4] 139  Running        CC - C foo c&
    -[3] 465  Stopped        mail morris
     [2] 687  Done(1)        foo.bar&
    
  2. To display the process ID for the job whose name begins with "m," enter:

    job -p %m
    

    Using the jobs reported in Example 1, the screen displays the following process ID:

    465
    

Files


/usr/bin/ksh Contains the Korn shell jobs built-in command.
/usr/bin/jobs Contains the jobs command.

Related Information

The bg command,csh command, fg command, kill command, ksh command, wait command.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]