Move everything from /var/adm to /var/log
[unleashed.git] / share / man / man1 / jobs.1
blobae4bf0b55799062039453511b08754745d89fd5d
1 .\"
2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
6 .\"
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
9 .\" documentation.
10 .\"
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
13 .\"
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group.  In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document.  The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
24 .\"
25 .\" This notice shall appear on any product containing this material.
26 .\"
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
30 .\"
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
35 .\"
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
41 .\"
42 .\"
43 .\" Copyright 1989 AT&T
44 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
45 .\" Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures
46 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved
47 .\"
48 .TH JOBS 1 "Nov 2, 2007"
49 .SH NAME
50 jobs, fg, bg, stop, notify \- control process execution
51 .SH SYNOPSIS
52 .SS "sh"
53 .LP
54 .nf
55 \fBjobs\fR [\fB-p\fR | \fB-l\fR] [% \fIjob_id\fR...]
56 .fi
58 .LP
59 .nf
60 \fBjobs\fR \fB-x\fR \fIcommand\fR [\fIarguments\fR]
61 .fi
63 .LP
64 .nf
65 \fBfg\fR [% \fIjob_id\fR...]
66 .fi
68 .LP
69 .nf
70 \fBbg\fR [% \fIjob_id\fR...]
71 .fi
73 .LP
74 .nf
75 \fBstop\fR % \fIjob_id\fR...
76 .fi
78 .LP
79 .nf
80 \fBstop\fR \fIpid\fR...
81 .fi
83 .SS "csh"
84 .LP
85 .nf
86 \fBjobs\fR [\fB-l\fR]
87 .fi
89 .LP
90 .nf
91 \fBfg\fR [% \fIjob_id\fR]
92 .fi
94 .LP
95 .nf
96 \fBbg\fR [% \fIjob_id\fR]...
97 .fi
99 .LP
101 \fBnotify\fR [% \fIjob_id\fR]...
106 \fBstop\fR % \fIjob_id\fR...
111 \fBstop\fR \fIpid\fR...
114 .SS "ksh"
117 \fBjobs\fR [\fB-lnp\fR] [% \fIjob_id\fR...]
122 \fBfg\fR [% \fIjob_id\fR...]
127 \fBbg\fR [% \fIjob_id\fR...]
132 \fBstop\fR % \fIjob_id\fR...
137 \fBstop\fR \fIpid\fR...
140 .SS "ksh93"
143 \fBjobs\fR [\fB-lnp\fR] [\fIjob_id\fR...]
148 \fBfg\fR [\fIjob_id\fR...]
153 \fBbg\fR [\fIjob_id\fR...]
156 .SH DESCRIPTION
157 .SS "sh"
160 When Job Control is enabled, the Bourne shell built-in \fBjobs\fR reports all
161 jobs that are stopped or executing in the background. If \fB%\fR\fIjob_id\fR is
162 omitted, all jobs that are stopped or running in the background is reported.
163 The following options modify or enhance the output of \fBjobs\fR:
165 .ne 2
167 \fB\fB-l\fR\fR
169 .RS 6n
170 Reports the process group \fBID\fR and working directory of the jobs.
174 .ne 2
176 \fB\fB-p\fR\fR
178 .RS 6n
179 Reports only the process group \fBID\fR of the jobs.
183 .ne 2
185 \fB\fB-x\fR\fR
187 .RS 6n
188 Replaces any \fIjob_id\fR found in \fIcommand\fR or \fIarguments\fR with the
189 corresponding process group \fBID\fR, and then executes \fIcommand\fR passing
190 it \fIarguments\fR.
195 When the shell is invoked as \fBjsh\fR, Job Control is enabled in addition to
196 all of the functionality described previously for \fBsh\fR. Typically Job
197 Control is enabled for the interactive shell only. Non-interactive shells
198 typically do not benefit from the added functionality of Job Control.
201 With Job Control enabled every command or pipeline the user enters at the
202 terminal is called a \fIjob_id\fR. All jobs exist in one of the following
203 states: foreground, background or stopped. These terms are defined as follows:
204 .RS +4
207 A job in the \fBforeground\fR has read and write access to the controlling
208 terminal.
210 .RS +4
213 A job in the \fBbackground\fR is denied read access and has conditional
214 write access to the controlling terminal (see \fBstty\fR(1))
216 .RS +4
219 A \fBstopped\fR job is a job that has been placed in a suspended state,
220 usually as a result of a \fBSIGTSTP\fR signal (see \fBsignal.h\fR(3HEAD)).
224 Every job that the shell starts is assigned a positive integer, called a
225 \fIjob_id number\fR which is tracked by the shell and are used as an identifier
226 to indicate a specific job. Additionally, the shell keeps track of the
227 \fBcurrent\fR and \fBprevious\fR jobs. The \fBcurrent job\fR is the most recent
228 job to be started or restarted. The \fBprevious job\fR is the first non-current
229 job.
232 The acceptable syntax for a Job Identifier is of the form:
235 \fB%\fR\fIjob_id\fR
238 where \fIjob_id\fR can be specified in any of the following formats:
240 .ne 2
242 \fB\fB%\fR or \fB+\fR\fR
244 .RS 13n
245 for the current job
249 .ne 2
251 \fB\fB\(mi\fR\fR
253 .RS 13n
254 for the previous job
258 .ne 2
260 \fB\fB?\fR\fI<string>\fR\fR
262 .RS 13n
263 specify the job for which the command line uniquely contains \fIstring\fR.
267 .ne 2
269 \fB\fIn\fR\fR
271 .RS 13n
272 for job number \fIn\fR, where \fIn\fR is a job number
276 .ne 2
278 \fB\fIpref\fR\fR
280 .RS 13n
281 where \fIpref\fR is a unique prefix of the command name (for example, if the
282 command \fBls \(mil name\fR were running in the background, it could be
283 referred to as \fB%ls\fR); \fIpref\fR cannot contain blanks unless it is
284 quoted.
289 When Job Control is enabled, \fBfg\fR resumes the execution of a stopped job in
290 the foreground, also moves an executing background job into the foreground. If
291 \fB%\fR\fIjob_id\fR is omitted the current job is assumed.
294 When Job Control is enabled, \fBbg\fR resumes the execution of a stopped job in
295 the background. If \fB%\fR\fIjob_id\fR is omitted the current job is assumed.
298 \fBstop\fR stops the execution of a background job(s) by using its
299 \fIjob_id\fR, or of any process by using its \fIpid\fR; see \fBps\fR(1).
300 .SS "csh"
303 The C shell built-in, \fBjobs\fR, without an argument, lists the active jobs
304 under job control.
306 .ne 2
308 \fB\fB-l\fR\fR
310 .RS 6n
311 List process \fBID\fRs, in addition to the normal information.
316 The shell associates a numbered \fIjob_id\fR with each command sequence to keep
317 track of those commands that are running in the background or have been stopped
318 with \fBTSTP\fR signals (typically Control-Z). When a command or command
319 sequence (semicolon-separated list) is started in the background using the
320 \fB&\fR metacharacter, the shell displays a line with the job number in
321 brackets and a list of associated process numbers:
324 \fB[1] 1234\fR
327 To see the current list of jobs, use the \fBjobs\fR built-in command. The job
328 most recently stopped (or put into the background if none are stopped) is
329 referred to as the \fBcurrent\fR job and is indicated with a `\fB+\fR'. The
330 previous job is indicated with a `\fB\(mi\fR\&'; when the current job is
331 terminated or moved to the foreground, this job takes its place (becomes the
332 new current job).
335 To manipulate jobs, refer to the \fBbg\fR, \fBfg\fR, \fBkill\fR, \fBstop\fR,
336 and \fB%\fR built-in commands.
339 A reference to a job begins with a `\fB%\fR'. By itself, the percent sign
340 refers to the current job.
342 .ne 2
344 \fB\fB%\fR \fB%+\fR \fB%%\fR\fR
346 .RS 12n
347 The current job.
351 .ne 2
353 \fB\fB%\(mi\fR\fR
355 .RS 12n
356 The previous job.
360 .ne 2
362 \fB\fB%\fR\fIj\fR\fR
364 .RS 12n
365 Refer to job \fIj\fR as in: `\fBkill\fR \fB-9\fR \fB%\fR\fIj\fR'. \fIj\fR can
366 be a job number, or a string that uniquely specifies the command line by which
367 it was started; `\fBfg %vi\fR' might bring a stopped \fBvi\fR job to the
368 foreground, for instance.
372 .ne 2
374 \fB\fB%?\fR\fIstring\fR\fR
376 .RS 12n
377 Specify the job for which the command line uniquely contains \fIstring\fR.
382 A job running in the background stops when it attempts to read from the
383 terminal. Background jobs can normally produce output, but this can be
384 suppressed using the `\fBstty tostop\fR' command.
387 \fBfg\fR brings the current or specified \fIjob_id\fR into the foreground.
390 \fBbg\fR runs the current or specified jobs in the background.
393 \fBstop\fR stops the execution of a background job(s) by using its
394 \fIjob_id\fR, or of any process by using its \fIpid\fR; see \fBps\fR(1).
397 \fBnotify\fR notifies the user asynchronously when the status of the current
398 job or specified jobs changes.
399 .SS "ksh"
402 \fBjobs\fR displays the status of the jobs that were started in the current
403 shell environment. When \fBjobs\fR reports the termination status of a job, the
404 shell removes its process \fBID\fR from the list of those known in the current
405 shell execution environment.
408 \fIjob_id\fR specifies the jobs for which the status is to be displayed. If no
409 \fIjob_id\fR is specified, the status information for all jobs are displayed.
412 The following options modify or enhance the output of \fBjobs\fR:
414 .ne 2
416 \fB\fB-l\fR\fR
418 .RS 6n
419 (The letter ell.) Provides more information about each job listed. This
420 information includes the job number, current job, process group \fBID\fR, state
421 and the command that formed the job.
425 .ne 2
427 \fB\fB-n\fR\fR
429 .RS 6n
430 Displays only jobs that have stopped or exited since last notified.
434 .ne 2
436 \fB\fB-p\fR\fR
438 .RS 6n
439 Displays only the process \fBID\fRs for the process group leaders of the
440 selected jobs.
445 By default, \fBjobs\fR displays the status of all the stopped jobs, running
446 background jobs, and all jobs whose status has changed and have not been
447 reported by the shell.
450 If the \fBmonitor\fR option of the \fBset\fR command is turned on, an
451 interactive shell associates a \fBjob\fR with each pipeline. It keeps a table
452 of current jobs, printed by the \fBjobs\fR command, and assigns them small
453 integer numbers. When a job is started asynchronously with \fB&\fR, the shell
454 prints a line which looks like:
457 \fB[1]\fR \fB1234\fR
460 indicating that the job, which was started asynchronously, was job number
461 \fB1\fR and had one (top-level) process, whose process id was \fB1234\fR.
464 If you are running a job and wish to do something else you can hit the key ^Z
465 (Control-Z) which sends a \fBSTOP\fR signal to the current job. The shell then
466 normally indicates that the job has been "\fBStopped\fR" (see \fBOUTPUT\fR
467 below), and print another prompt. You can then manipulate the state of this
468 job, putting it in the background with the \fBbg\fR command, or run some other
469 commands and then eventually bring the job back into the foreground with the
470 foreground command \fBfg\fR. A ^Z takes effect immediately and is like an
471 interrupt, in that pending output and unread input are discarded when it is
472 typed.
475 There are several ways to refer to jobs in the shell. A job can be referred to
476 by the process id of any process of the job or by one of the following:
478 .ne 2
480 \fB\fB%\fR\fInumber\fR\fR
482 .RS 12n
483 The job with the specified number.
487 .ne 2
489 \fB\fB%\fR\fIstring\fR\fR
491 .RS 12n
492 Any job whose command line begins with \fIstring\fR; works only in the
493 interactive mode when the history file is active.
497 .ne 2
499 \fB\fB%?\fR\fIstring\fR\fR
501 .RS 12n
502 Any job whose command line contains \fIstring\fR; works only in the interactive
503 mode when the history file is active.
507 .ne 2
509 \fB\fB%%\fR\fR
511 .RS 12n
512 Current job.
516 .ne 2
518 \fB\fB%+\fR\fR
520 .RS 12n
521 Equivalent to \fB%%\fR.
525 .ne 2
527 \fB\fB%\(mi\fR\fR
529 .RS 12n
530 Previous job.
535 The shell learns immediately whenever a process changes state. It normally
536 informs you whenever a job becomes blocked so that no further progress is
537 possible, but only just before it prints a prompt. This is done so that it does
538 not otherwise disturb your work. When the monitor mode is on, each background
539 job that completes triggers any trap set for \fBCHLD\fR. When you try to leave
540 the shell while jobs are running or stopped, you are warned that `You have
541 stopped (running) jobs.' You can use the \fBjobs\fR command to see what they
542 are. If you do this or immediately try to exit again, the shell does not warn
543 you a second time, and the stopped jobs are terminated.
546 \fBfg\fR moves a background job from the current environment into the
547 foreground. Using \fBfg\fR to place a job in the foreground removes its process
548 \fBID\fR from the list of those known in the current shell execution
549 environment. The \fBfg\fR command is available only on systems that support job
550 control. If \fIjob_id\fR is not specified, the current job is brought into the
551 foreground.
554 \fBbg\fR resumes suspended jobs from the current environment by running them as
555 background jobs. If the job specified by \fIjob_id\fR is already a running
556 background job, \fBbg\fR has no effect and exits successfully. Using \fBbg\fR
557 to place a job into the background causes its process \fBID\fR to become `known
558 in the current shell execution environment, as if it had been started as an
559 asynchronous list. The \fBbg\fR command is available only on systems that
560 support job control. If \fIjob_id\fR is not specified, the current job is
561 placed in the background.
564 \fBstop\fR stops the execution of a background job(s) by using its
565 \fIjob_id\fR, or of any process by using its \fIpid\fR. See \fBps\fR(1).
566 .SS "ksh93"
569 \fBjobs\fR displays information about specified jobs that were started by the
570 current shell environment on standard output. The information contains the job
571 number enclosed in \fB[...]\fR, the status, and the command line that started
572 the job.
575 If \fIjob_id\fR is omitted, \fBjobs\fR displays the status of all stopped jobs,
576 background jobs, and all jobs whose status has changed since last reported by
577 the shell.
580 When \fBjobs\fR reports the termination status of a job, the shell removes the
581 job from the list of known jobs in the current shell environment.
584 The following options modify or enhances the output of \fBjobs\fR:
586 .ne 2
588 \fB\fB-l\fR\fR
590 .RS 6n
591 Displays process IDs after the job number in addition to the usual information.
595 .ne 2
597 \fB\fB-n\fR\fR
599 .RS 6n
600 Displays only the jobs whose status has changed since the last prompt was
601 displayed.
605 .ne 2
607 \fB\fB-p\fR\fR
609 .RS 6n
610 Displays the process group leader IDs for the specified jobs.
615 \fIjob_id\fR can be specified to \fBjobs\fR, \fBfg\fR, and \fBbg\fR as one of
616 the following:
618 .ne 2
620 \fB\fInumber\fR\fR
622 .RS 12n
623 The process id of \fBjob\fR.
627 .ne 2
629 \fB\fB-\fR\fInumber\fR\fR
631 .RS 12n
632 The process group id of \fBjob\fR.
636 .ne 2
638 \fB\fB%\fR\fInumber\fR\fR
640 .RS 12n
641 The job number.
645 .ne 2
647 \fB\fB%\fR\fIstring\fR\fR
649 .RS 12n
650 The job whose name begins with \fIstring\fR.
654 .ne 2
656 \fB\fB%?\fR\fIstring\fR\fR
658 .RS 12n
659 The job whose name contains \fIstring\fR.
663 .ne 2
665 \fB\fB%+\fR\fR
669 \fB\fB%%\fR\fR
671 .RS 12n
672 The current job.
676 .ne 2
678 \fB\fB%-\fR\fR
680 .RS 12n
681 The previous job.
686 \fBfg\fR places the specified jobs into the foreground in sequence and sends a
687 \fBCONT\fR signal to start each running. If \fIjob_id\fR is omitted, the most
688 recently started or stopped background job is moved to the foreground.
691 \fBbg\fR places the specified jobs into the background and sends a \fBCONT\fR
692 signal to start them running. If \fIjob_id\fR is omitted, the most recently
693 started or stopped background job is resumed or continued in the background.
694 .SH OUTPUT
697 If the \fB-p\fR option is specified, the output consists of one line for each
698 process \fBID\fR:
701 \fB"%d\en",\fR \fI"process ID"\fR
704 Otherwise, if the \fB-l\fR option is not specified, the output is a series of
705 lines of the form:
708 \fB"[%d] %c %s %s\en"\fR, \fIjob-number\fR, \fIcurrent\fR, \fIstate\fR,
709 \fIcommand\fR
712 where the fields are as follows:
714 .ne 2
716 \fB\fIcurrent\fR\fR
718 .RS 14n
719 The character \fB+\fR identifies the job that would be used as a default for
720 the \fBfg\fR or \fBbg\fR commands. This job can also be specified using the
721 \fIjob_id\fR \fB%+\fR or \fB%%\fR \fB\&.\fR The character \fB\(mi\fR identifies
722 the job that would become the default if the current default job were to exit;
723 this job can also be specified using the \fIjob_id\fR \fB%\(mi\fR \fB\&.\fR For
724 other jobs, this field is a space character. At most, one job can be identified
725 with \fB+\fR and at most one job can be identified with \fB\(mi\fR\&. If there
726 is any suspended job, then the current job is a suspended job. If there are at
727 least two suspended jobs, then the previous job is also a suspended job.
731 .ne 2
733 \fB\fIjob-number\fR\fR
735 .RS 14n
736 A number that can be used to identify the process group to the \fBwait\fR,
737 \fBfg\fR, \fBbg,\fR and \fBkill\fR utilities. Using these utilities, the job
738 can be identified by prefixing the job number with \fB%\fR.
742 .ne 2
744 \fB\fIstate\fR\fR
746 .RS 14n
747 One of the following strings in the POSIX Locale:
749 .ne 2
751 \fB\fBRunning\fR\fR
753 .RS 20n
754 Indicates that the job has not been suspended by a signal and has not exited.
758 .ne 2
760 \fB\fBDone\fR\fR
762 .RS 20n
763 Indicates that the job completed and returned exit status zero.
767 .ne 2
769 \fB\fBDone\fR(\fIcode\fR)\fR
771 .RS 20n
772 Indicates that the job completed normally and that it exited with the specified
773 \fBnon-zero\fR exit status, \fIcode\fR, expressed as a decimal number.
777 .ne 2
779 \fB\fBStopped\fR\fR
781 .RS 20n
782 Indicates that the job was stopped.
786 .ne 2
788 \fB\fBStopped(SIGTSTP)\fR\fR
790 .RS 20n
791 Indicates that the job was suspended by the \fBSIGTSTP\fR signal.
795 .ne 2
797 \fB\fBStopped(SIGSTOP)\fR\fR
799 .RS 20n
800 Indicates that the job was suspended by the \fBSIGSTOP\fR signal.
804 .ne 2
806 \fB\fBStopped(SIGTTIN)\fR\fR
808 .RS 20n
809 Indicates that the job was suspended by the \fBSIGTTIN\fR signal.
813 .ne 2
815 \fB\fBStopped(SIGTTOU)\fR\fR
817 .RS 20n
818 Indicates that the job was suspended by the \fBSIGTTOU\fR signal.
821 The implementation can substitute the string \fBSuspended\fR in place of
822 \fBStopped\fR. If the job was terminated by a signal, the format of \fBstate\fR
823 is unspecified, but it is visibly distinct from all of the other \fBstate\fR
824 formats shown here and indicates the name or description of the signal causing
825 the termination.
829 .ne 2
831 \fB\fIcommand\fR\fR
833 .RS 14n
834 The associated command that was specified to the shell.
839 If the \fB-l\fR option is specified, a field containing the process group
840 \fBID\fR is inserted before the \fBstate\fR field. Also, more processes in a
841 process group can be output on separate lines, using only the process \fBID\fR
842 and \fBcommand\fR fields.
843 .SH ENVIRONMENT VARIABLES
846 See \fBenviron\fR(5) for descriptions of the following environment variables
847 that affect the execution of \fBjobs\fR, \fBfg\fR, and \fBbg\fR: \fBLANG\fR,
848 \fBLC_ALL\fR, \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
849 .SH EXIT STATUS
850 .SS "sh, csh, ksh"
853 The following exit values are returned for \fBjobs\fR, \fBfg\fR, and \fBbg\fR:
855 .ne 2
857 \fB\fB0\fR\fR
859 .RS 6n
860 Successful completion.
864 .ne 2
866 \fB\fB>0\fR\fR
868 .RS 6n
869 An error occurred.
872 .SS "ksh93"
875 The following exit values are returned for \fBjobs\fR:
877 .ne 2
879 \fB\fB0\fR\fR
881 .RS 6n
882 The information for each job is written to standard output.
886 .ne 2
888 \fB\fB>0\fR\fR
890 .RS 6n
891 One or more jobs does not exist.
896 The following exit values are returned for \fBfg\fR:
898 .ne 2
900 \fB\fBexit status of last job\fR\fR
902 .RS 27n
903 One or more jobs has been brought into the foreground.
907 .ne 2
909 \fB\fBnon-zero\fR\fR
911 .RS 27n
912 One or more jobs does not exist or has completed.
917 The following exit values are returned for \fBbg\fR:
919 .ne 2
921 \fB\fB0\fR\fR
923 .RS 6n
924 All background jobs are started.
928 .ne 2
930 \fB\fB>0\fR\fR
932 .RS 6n
933 One more jobs does not exist or there are no background jobs.
936 .SH ATTRIBUTES
939 See \fBattributes\fR(5) for descriptions of the following attributes:
940 .SS "csh, sh, ksh"
945 box;
946 c | c
947 l | l .
948 ATTRIBUTE TYPE  ATTRIBUTE VALUE
950 Interface Stability     Committed
952 Standard        See \fBstandards\fR(5).
955 .SS "ksh93"
960 box;
961 c | c
962 l | l .
963 ATTRIBUTE TYPE  ATTRIBUTE VALUE
965 Interface Stability     Uncommitted
968 .SH SEE ALSO
971 \fBcsh\fR(1), \fBkill\fR(1), \fBksh\fR(1), \fBksh93\fR(1), \fBps\fR(1),
972 \fBsh\fR(1), \fBstop\fR(1), \fBshell_builtins\fR(1), \fBstty\fR(1),
973 \fBwait\fR(1), \fBsignal.h\fR(3HEAD), \fBattributes\fR(5), \fBenviron\fR(5),
974 \fBstandards\fR(5)