- 论坛徽章:
- 5
|
回复 #14 ly5066113 的帖子
Tim,折杀我了。
我觉得要先弄清楚sub shell的定义。
查了些资料,发现subshell的定义有些混乱。
bashMan:
Each command in a pipeline is executed as a separate process (i.e., in a subshell).
When a simple command other than a builtin or shell function is to be executed, it is invoked in a
separate execution environment that consists of the following. Unless otherwise noted, the values are
inherited from the shell.
这个separate execution是subshell吗?
A. 在当前shell执行外部命令,如shell> date, 是fork+exec, 算不是subshell?
B. ()是fork一个child shell,该child再fork+exec来执行命令。这个subshell和A中的"subshell"显然是不同的。
UNIX: The Textbook, by Syed Mansoor Sarvar, Robert Koretsky and Syed Aqeel Sarvar中提到:
A child shell is also called subshell
问题是fork+exec是fork一个child shell,然后在该child shell中exec.
而执行脚本(shell>scriptname)时,是fort一个child shell A,该child shell A再fork一个child shell B, 在B中再exec.
那么child shell是指哪种情况?
UNIX at Fermilab中的Important UNIX Concepts:
When you give the shell a command associated with a compiled executable or shell script, the shell
creates, or forks, a new process called a subshell.
外部命令也在subshell中执行。
To execute most built-in commands, the shell forks a subshell which executes the command directly (no
exec system call). For the built-in commands cd, set, alias and source, the current shell executes the
command; no subshell is forked.
shell> built-inCommands这样执行时,大部分内部命令也是在subshell中执行。
可见,UNIX at Fermilab认为fork 一个child shell就是subshell, 不管是fork-fork+exec, 还是 fork+exec。
[ 本帖最后由 blackold 于 2009-6-14 10:27 编辑 ] |
|