预计阅读本页时间:-
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
广告:个人专属 VPN,独立 IP,无限流量,多机房切换,还可以屏蔽广告和恶意软件,每月最低仅 5 美元
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:[1]
[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:[2]
[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.
[1] 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.
[2] 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 Table 2-1 and Table 2-5