第130页 | Learning the Bash Shell | 阅读 ‧ 电子书库

同步阅读进度,多语言翻译,过滤屏幕蓝光,评论分享,更多完整功能,更好读书体验,试试 阅读 ‧ 电子书库

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:[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

请支持我们,让我们可以支付服务器费用。
使用微信支付打赏


上一页 · 目录下一页


下载 · 书页 · 阅读 ‧ 电子书库