Process IDs and Job Numbers

8.1 Process IDs and Job Numbers

UNIX gives all processes numbers, called process IDs , when they are created. You will notice that when you run a command in the background by appending & to it, the shell responds with a line that looks like this:

$ alice &[1] 93

In this example, 93 is the process ID for the alice process. The [1] is a job number assigned by the shell (not the operating system). What's the difference? Job numbers refer to background processes that are currently running under your shell, while process IDs refer to all processes currently running on the entire system, for all users. The term job basically refers to a command line that was invoked from your shell.

If you start up additional background jobs while the first one is still running, the shell will number them 2, 3, etc. For example:

$ duchess &[2] 102
$ hatter &[3] 104

Clearly, 1, 2, and 3 are easier to remember than 93, 102, and 104!

The shell includes job numbers in messages it prints when a background job completes, like this: [2]

[2] The messages are, by default, printed before the next prompt is displayed so as not to interrupt any output on the display. You can make the notification messages display immediately by using set -b .

[1]+ Done alice

We'll explain what the plus sign means soon. If the job exits with non-zero status (see Chapter 5 ), the shell will indicate the exit status: [3]

[3] In POSIX mode, the message is slightly different: " [1]+ Done(1) alice ". The number in parentheses is the exit status of the job. POSIX mode can be selected via the set command or by starting bash in POSIX mode. For further information, see Appendix B, Table 2.1 " and Table 2.5

[1]+ Exit 1 alice

The shell prints other types of messages when certain abnormal things happen to background jobs; we'll see these later in this chapter.


Learning the Bash Shell
Learning the bash Shell: Unix Shell Programming (In a Nutshell (OReilly))
ISBN: 0596009658
EAN: 2147483647
Year: 1998
Pages: 104

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: