Home
Theory
News
Documentation
Download
Bio
The jobs facility lets you reference an existing job, access data about an existing job, or display a list of current jobs.

You reference the process ID of a job with a percent sign, and either the job number, a string from the job command text, '%' for default job, or '-' for previous default job:

mpsh$ kill -9 %3
mpsh$ kill -9 %gcc
mpsh$ kill -9 %%
mpsh$ kill -9 %-

You can get other information about a job by adding a dot and a field name to a job reference. The available fields are:

hist - History entry number.
text - The text of the command.
dir - The directory the command was executed in.

For example:

Go to the directory the current vi job was started in:

mpsh$ cd %vi.dir

Show the full history details for the current make job:

mpsh$ history %make.hist

The jobs command displays the current jobs. You can display the short form, long form, user-specified format, or full details for one entry. ("jobs" with no arguments is short for "jobs -s".)

mpsh$ jobs [%job]
mpsh$ jobs -s [%job]
mpsh$ jobs -l [%job]
mpsh$ jobs format-string [%job]

The fields displayed by the jobs command are controlled by format strings, one letter for each field. The simple "jobs -s" display is controlled by the mpsh-jobs-disp environment variable (default: anrcm, for: name, number, run status, command text, optional multi-process count), and the long format is controlled by the mpsh-jobs-disp-l environment variable (default: aeRhfcm, for: name, elapsed time, long run status, history entry number, foreground order, command text, optional multi-process count). You can also specify an arbitrary format as the argument to jobs.

The fields available via the format strings are:

c - Command
C - Command, limited to 20 characters
a - Name
n - Number
h - History number
e - Elapsed time
t - Time started
r - Run status
R - Long run status
f - fg default
d - Directory
D - Directory, limited to 20 characters
m - smp count (optional)
M - smp count
p - pid

For example:

Show all current jobs, long format:

mpsh$ jobs -l

Show current "make" job, long format:

mpsh$ jobs -l %make

Show the elapsed time and command for current "make" job,

mpsh$ jobs ec %make

Another way to change directory to where a job was started:

mpsh$ cd (jobs d %make)

Make the jobs display approximate bash/ksh/etc behaviour:

mpsh$ setenv mpsh-jobs-disp=nfRc
mpsh$ setenv mpsh-jobs-disp-l=nfpRc

The width of the fields displayed changes depending on the data, so don't try to filter the output of jobs based on strict character position.

You can delete a job with the "-d" option. This simply makes mpsh forget about the job. The process will continue to run, but it will not appear in the jobs display, and you will not receive notification when it exits. (You can still find the status of a deleted job by looking up its history entry.)

mpsh$ jobs -d %job

You can also name a job. The job name can then be used for job expansion: %Name, job exit notification, and can be displayed in jobs or jobs -l with the "a" format field.

mpsh$ jobs -n %job name