UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 38.3 Managing Processes: Overall Concepts Chapter 38
Starting, Stopping, and Killing Processes
Next: 38.5 The ps Command
 

38.4 Subshells

In UNIX, when a program starts another program (more exactly, when a process starts another process), the new process runs as a subprocess (38.3) or child process. [1] When a shell starts another shell, the new shell is called a subshell. [2]

[1] This isn't true when the subprocess is execd from the parent process without a fork first. Article 38.2 explains.

[2] When you use the shell's exec (45.7) command, it does not start a subprocess.

So what? There are some important things to know about it: the child process gets a copy of its parent's environment. Any changes in the environment of the child process aren't passed to its parent. "Still," I hear you say, "so what??"

If you use the exit command, a subshell (or any shell) will terminate. In a script, when the shell reads the end of file, that does an implicit exit. On the command line, an end-of-input character (usually CTRL-d) will do the same thing. Article 44.11 explains how exit sets a shell's exit status.

- JP


Previous: 38.3 Managing Processes: Overall Concepts UNIX Power ToolsNext: 38.5 The ps Command
38.3 Managing Processes: Overall Concepts Book Index38.5 The ps Command

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System