2 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved
3 .\" Copyright 1989 AT&T
4 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
5 .\" Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures
6 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
7 .\" http://www.opengroup.org/bookstore/.
8 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
9 .\" This notice shall appear on any product containing this material.
10 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
11 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
12 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
13 .TH JOBS 1 "Nov 2, 2007"
15 jobs, fg, bg, stop, notify \- control process execution
20 \fBjobs\fR [\fB-p\fR | \fB-l\fR] [% \fIjob_id\fR...]
25 \fBjobs\fR \fB-x\fR \fIcommand\fR [\fIarguments\fR]
30 \fBfg\fR [% \fIjob_id\fR...]
35 \fBbg\fR [% \fIjob_id\fR...]
40 \fBstop\fR % \fIjob_id\fR...
45 \fBstop\fR \fIpid\fR...
56 \fBfg\fR [% \fIjob_id\fR]
61 \fBbg\fR [% \fIjob_id\fR]...
66 \fBnotify\fR [% \fIjob_id\fR]...
71 \fBstop\fR % \fIjob_id\fR...
76 \fBstop\fR \fIpid\fR...
82 \fBjobs\fR [\fB-lnp\fR] [% \fIjob_id\fR...]
87 \fBfg\fR [% \fIjob_id\fR...]
92 \fBbg\fR [% \fIjob_id\fR...]
97 \fBstop\fR % \fIjob_id\fR...
102 \fBstop\fR \fIpid\fR...
108 \fBjobs\fR [\fB-lnp\fR] [\fIjob_id\fR...]
113 \fBfg\fR [\fIjob_id\fR...]
118 \fBbg\fR [\fIjob_id\fR...]
125 When Job Control is enabled, the Bourne shell built-in \fBjobs\fR reports all
126 jobs that are stopped or executing in the background. If \fB%\fR\fIjob_id\fR is
127 omitted, all jobs that are stopped or running in the background is reported.
128 The following options modify or enhance the output of \fBjobs\fR:
135 Reports the process group \fBID\fR and working directory of the jobs.
144 Reports only the process group \fBID\fR of the jobs.
153 Replaces any \fIjob_id\fR found in \fIcommand\fR or \fIarguments\fR with the
154 corresponding process group \fBID\fR, and then executes \fIcommand\fR passing
160 When the shell is invoked as \fBjsh\fR, Job Control is enabled in addition to
161 all of the functionality described previously for \fBsh\fR. Typically Job
162 Control is enabled for the interactive shell only. Non-interactive shells
163 typically do not benefit from the added functionality of Job Control.
166 With Job Control enabled every command or pipeline the user enters at the
167 terminal is called a \fIjob_id\fR. All jobs exist in one of the following
168 states: foreground, background or stopped. These terms are defined as follows:
172 A job in the \fBforeground\fR has read and write access to the controlling
178 A job in the \fBbackground\fR is denied read access and has conditional
179 write access to the controlling terminal (see \fBstty\fR(1))
184 A \fBstopped\fR job is a job that has been placed in a suspended state,
185 usually as a result of a \fBSIGTSTP\fR signal (see \fBsignal.h\fR(3HEAD)).
189 Every job that the shell starts is assigned a positive integer, called a
190 \fIjob_id number\fR which is tracked by the shell and are used as an identifier
191 to indicate a specific job. Additionally, the shell keeps track of the
192 \fBcurrent\fR and \fBprevious\fR jobs. The \fBcurrent job\fR is the most recent
193 job to be started or restarted. The \fBprevious job\fR is the first non-current
197 The acceptable syntax for a Job Identifier is of the form:
203 where \fIjob_id\fR can be specified in any of the following formats:
207 \fB\fB%\fR or \fB+\fR\fR
225 \fB\fB?\fR\fI<string>\fR\fR
228 specify the job for which the command line uniquely contains \fIstring\fR.
237 for job number \fIn\fR, where \fIn\fR is a job number
246 where \fIpref\fR is a unique prefix of the command name (for example, if the
247 command \fBls \(mil name\fR were running in the background, it could be
248 referred to as \fB%ls\fR); \fIpref\fR cannot contain blanks unless it is
254 When Job Control is enabled, \fBfg\fR resumes the execution of a stopped job in
255 the foreground, also moves an executing background job into the foreground. If
256 \fB%\fR\fIjob_id\fR is omitted the current job is assumed.
259 When Job Control is enabled, \fBbg\fR resumes the execution of a stopped job in
260 the background. If \fB%\fR\fIjob_id\fR is omitted the current job is assumed.
263 \fBstop\fR stops the execution of a background job(s) by using its
264 \fIjob_id\fR, or of any process by using its \fIpid\fR; see \fBps\fR(1).
268 The C shell built-in, \fBjobs\fR, without an argument, lists the active jobs
276 List process \fBID\fRs, in addition to the normal information.
281 The shell associates a numbered \fIjob_id\fR with each command sequence to keep
282 track of those commands that are running in the background or have been stopped
283 with \fBTSTP\fR signals (typically Control-Z). When a command or command
284 sequence (semicolon-separated list) is started in the background using the
285 \fB&\fR metacharacter, the shell displays a line with the job number in
286 brackets and a list of associated process numbers:
292 To see the current list of jobs, use the \fBjobs\fR built-in command. The job
293 most recently stopped (or put into the background if none are stopped) is
294 referred to as the \fBcurrent\fR job and is indicated with a `\fB+\fR'. The
295 previous job is indicated with a `\fB\(mi\fR\&'; when the current job is
296 terminated or moved to the foreground, this job takes its place (becomes the
300 To manipulate jobs, refer to the \fBbg\fR, \fBfg\fR, \fBkill\fR, \fBstop\fR,
301 and \fB%\fR built-in commands.
304 A reference to a job begins with a `\fB%\fR'. By itself, the percent sign
305 refers to the current job.
309 \fB\fB%\fR \fB%+\fR \fB%%\fR\fR
330 Refer to job \fIj\fR as in: `\fBkill\fR \fB-9\fR \fB%\fR\fIj\fR'. \fIj\fR can
331 be a job number, or a string that uniquely specifies the command line by which
332 it was started; `\fBfg %vi\fR' might bring a stopped \fBvi\fR job to the
333 foreground, for instance.
339 \fB\fB%?\fR\fIstring\fR\fR
342 Specify the job for which the command line uniquely contains \fIstring\fR.
347 A job running in the background stops when it attempts to read from the
348 terminal. Background jobs can normally produce output, but this can be
349 suppressed using the `\fBstty tostop\fR' command.
352 \fBfg\fR brings the current or specified \fIjob_id\fR into the foreground.
355 \fBbg\fR runs the current or specified jobs in the background.
358 \fBstop\fR stops the execution of a background job(s) by using its
359 \fIjob_id\fR, or of any process by using its \fIpid\fR; see \fBps\fR(1).
362 \fBnotify\fR notifies the user asynchronously when the status of the current
363 job or specified jobs changes.
367 \fBjobs\fR displays the status of the jobs that were started in the current
368 shell environment. When \fBjobs\fR reports the termination status of a job, the
369 shell removes its process \fBID\fR from the list of those known in the current
370 shell execution environment.
373 \fIjob_id\fR specifies the jobs for which the status is to be displayed. If no
374 \fIjob_id\fR is specified, the status information for all jobs are displayed.
377 The following options modify or enhance the output of \fBjobs\fR:
384 (The letter ell.) Provides more information about each job listed. This
385 information includes the job number, current job, process group \fBID\fR, state
386 and the command that formed the job.
395 Displays only jobs that have stopped or exited since last notified.
404 Displays only the process \fBID\fRs for the process group leaders of the
410 By default, \fBjobs\fR displays the status of all the stopped jobs, running
411 background jobs, and all jobs whose status has changed and have not been
412 reported by the shell.
415 If the \fBmonitor\fR option of the \fBset\fR command is turned on, an
416 interactive shell associates a \fBjob\fR with each pipeline. It keeps a table
417 of current jobs, printed by the \fBjobs\fR command, and assigns them small
418 integer numbers. When a job is started asynchronously with \fB&\fR, the shell
419 prints a line which looks like:
425 indicating that the job, which was started asynchronously, was job number
426 \fB1\fR and had one (top-level) process, whose process id was \fB1234\fR.
429 If you are running a job and wish to do something else you can hit the key ^Z
430 (Control-Z) which sends a \fBSTOP\fR signal to the current job. The shell then
431 normally indicates that the job has been "\fBStopped\fR" (see \fBOUTPUT\fR
432 below), and print another prompt. You can then manipulate the state of this
433 job, putting it in the background with the \fBbg\fR command, or run some other
434 commands and then eventually bring the job back into the foreground with the
435 foreground command \fBfg\fR. A ^Z takes effect immediately and is like an
436 interrupt, in that pending output and unread input are discarded when it is
440 There are several ways to refer to jobs in the shell. A job can be referred to
441 by the process id of any process of the job or by one of the following:
445 \fB\fB%\fR\fInumber\fR\fR
448 The job with the specified number.
454 \fB\fB%\fR\fIstring\fR\fR
457 Any job whose command line begins with \fIstring\fR; works only in the
458 interactive mode when the history file is active.
464 \fB\fB%?\fR\fIstring\fR\fR
467 Any job whose command line contains \fIstring\fR; works only in the interactive
468 mode when the history file is active.
486 Equivalent to \fB%%\fR.
500 The shell learns immediately whenever a process changes state. It normally
501 informs you whenever a job becomes blocked so that no further progress is
502 possible, but only just before it prints a prompt. This is done so that it does
503 not otherwise disturb your work. When the monitor mode is on, each background
504 job that completes triggers any trap set for \fBCHLD\fR. When you try to leave
505 the shell while jobs are running or stopped, you are warned that `You have
506 stopped (running) jobs.' You can use the \fBjobs\fR command to see what they
507 are. If you do this or immediately try to exit again, the shell does not warn
508 you a second time, and the stopped jobs are terminated.
511 \fBfg\fR moves a background job from the current environment into the
512 foreground. Using \fBfg\fR to place a job in the foreground removes its process
513 \fBID\fR from the list of those known in the current shell execution
514 environment. The \fBfg\fR command is available only on systems that support job
515 control. If \fIjob_id\fR is not specified, the current job is brought into the
519 \fBbg\fR resumes suspended jobs from the current environment by running them as
520 background jobs. If the job specified by \fIjob_id\fR is already a running
521 background job, \fBbg\fR has no effect and exits successfully. Using \fBbg\fR
522 to place a job into the background causes its process \fBID\fR to become `known
523 in the current shell execution environment, as if it had been started as an
524 asynchronous list. The \fBbg\fR command is available only on systems that
525 support job control. If \fIjob_id\fR is not specified, the current job is
526 placed in the background.
529 \fBstop\fR stops the execution of a background job(s) by using its
530 \fIjob_id\fR, or of any process by using its \fIpid\fR. See \fBps\fR(1).
534 \fBjobs\fR displays information about specified jobs that were started by the
535 current shell environment on standard output. The information contains the job
536 number enclosed in \fB[...]\fR, the status, and the command line that started
540 If \fIjob_id\fR is omitted, \fBjobs\fR displays the status of all stopped jobs,
541 background jobs, and all jobs whose status has changed since last reported by
545 When \fBjobs\fR reports the termination status of a job, the shell removes the
546 job from the list of known jobs in the current shell environment.
549 The following options modify or enhances the output of \fBjobs\fR:
556 Displays process IDs after the job number in addition to the usual information.
565 Displays only the jobs whose status has changed since the last prompt was
575 Displays the process group leader IDs for the specified jobs.
580 \fIjob_id\fR can be specified to \fBjobs\fR, \fBfg\fR, and \fBbg\fR as one of
588 The process id of \fBjob\fR.
594 \fB\fB-\fR\fInumber\fR\fR
597 The process group id of \fBjob\fR.
603 \fB\fB%\fR\fInumber\fR\fR
612 \fB\fB%\fR\fIstring\fR\fR
615 The job whose name begins with \fIstring\fR.
621 \fB\fB%?\fR\fIstring\fR\fR
624 The job whose name contains \fIstring\fR.
651 \fBfg\fR places the specified jobs into the foreground in sequence and sends a
652 \fBCONT\fR signal to start each running. If \fIjob_id\fR is omitted, the most
653 recently started or stopped background job is moved to the foreground.
656 \fBbg\fR places the specified jobs into the background and sends a \fBCONT\fR
657 signal to start them running. If \fIjob_id\fR is omitted, the most recently
658 started or stopped background job is resumed or continued in the background.
662 If the \fB-p\fR option is specified, the output consists of one line for each
666 \fB"%d\en",\fR \fI"process ID"\fR
669 Otherwise, if the \fB-l\fR option is not specified, the output is a series of
673 \fB"[%d] %c %s %s\en"\fR, \fIjob-number\fR, \fIcurrent\fR, \fIstate\fR,
677 where the fields are as follows:
684 The character \fB+\fR identifies the job that would be used as a default for
685 the \fBfg\fR or \fBbg\fR commands. This job can also be specified using the
686 \fIjob_id\fR \fB%+\fR or \fB%%\fR \fB\&.\fR The character \fB\(mi\fR identifies
687 the job that would become the default if the current default job were to exit;
688 this job can also be specified using the \fIjob_id\fR \fB%\(mi\fR \fB\&.\fR For
689 other jobs, this field is a space character. At most, one job can be identified
690 with \fB+\fR and at most one job can be identified with \fB\(mi\fR\&. If there
691 is any suspended job, then the current job is a suspended job. If there are at
692 least two suspended jobs, then the previous job is also a suspended job.
698 \fB\fIjob-number\fR\fR
701 A number that can be used to identify the process group to the \fBwait\fR,
702 \fBfg\fR, \fBbg,\fR and \fBkill\fR utilities. Using these utilities, the job
703 can be identified by prefixing the job number with \fB%\fR.
712 One of the following strings in the POSIX Locale:
719 Indicates that the job has not been suspended by a signal and has not exited.
728 Indicates that the job completed and returned exit status zero.
734 \fB\fBDone\fR(\fIcode\fR)\fR
737 Indicates that the job completed normally and that it exited with the specified
738 \fBnon-zero\fR exit status, \fIcode\fR, expressed as a decimal number.
747 Indicates that the job was stopped.
753 \fB\fBStopped(SIGTSTP)\fR\fR
756 Indicates that the job was suspended by the \fBSIGTSTP\fR signal.
762 \fB\fBStopped(SIGSTOP)\fR\fR
765 Indicates that the job was suspended by the \fBSIGSTOP\fR signal.
771 \fB\fBStopped(SIGTTIN)\fR\fR
774 Indicates that the job was suspended by the \fBSIGTTIN\fR signal.
780 \fB\fBStopped(SIGTTOU)\fR\fR
783 Indicates that the job was suspended by the \fBSIGTTOU\fR signal.
786 The implementation can substitute the string \fBSuspended\fR in place of
787 \fBStopped\fR. If the job was terminated by a signal, the format of \fBstate\fR
788 is unspecified, but it is visibly distinct from all of the other \fBstate\fR
789 formats shown here and indicates the name or description of the signal causing
799 The associated command that was specified to the shell.
804 If the \fB-l\fR option is specified, a field containing the process group
805 \fBID\fR is inserted before the \fBstate\fR field. Also, more processes in a
806 process group can be output on separate lines, using only the process \fBID\fR
807 and \fBcommand\fR fields.
808 .SH ENVIRONMENT VARIABLES
811 See \fBenviron\fR(5) for descriptions of the following environment variables
812 that affect the execution of \fBjobs\fR, \fBfg\fR, and \fBbg\fR: \fBLANG\fR,
813 \fBLC_ALL\fR, \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
818 The following exit values are returned for \fBjobs\fR, \fBfg\fR, and \fBbg\fR:
825 Successful completion.
840 The following exit values are returned for \fBjobs\fR:
847 The information for each job is written to standard output.
856 One or more jobs does not exist.
861 The following exit values are returned for \fBfg\fR:
865 \fB\fBexit status of last job\fR\fR
868 One or more jobs has been brought into the foreground.
877 One or more jobs does not exist or has completed.
882 The following exit values are returned for \fBbg\fR:
889 All background jobs are started.
898 One more jobs does not exist or there are no background jobs.
904 See \fBattributes\fR(5) for descriptions of the following attributes:
913 ATTRIBUTE TYPE ATTRIBUTE VALUE
915 Interface Stability Committed
917 Standard See \fBstandards\fR(5).
928 ATTRIBUTE TYPE ATTRIBUTE VALUE
930 Interface Stability Uncommitted
936 \fBcsh\fR(1), \fBkill\fR(1), \fBksh\fR(1), \fBksh93\fR(1), \fBps\fR(1),
937 \fBsh\fR(1), \fBstop\fR(1), \fBshell_builtins\fR(1), \fBstty\fR(1),
938 \fBwait\fR(1), \fBsignal.h\fR(3HEAD), \fBattributes\fR(5), \fBenviron\fR(5),