Starting, Stopping, and Killing Processes
In UNIX, when a program starts another program
(more exactly, when a process starts another process),
the new process runs as a
or child process.
When a shell starts another shell, the new shell is called a subshell
some important things to know
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??"
Shell scripts are run in a subshell (unless you use the
to start the script).
If the script makes changes to the environment of its (sub)shell,
the parent shell won't see those changes.
If the script uses cd
, it doesn't change the current directory
in the parent shell.
If the script
changes the value of the TZ
(or any) environment variable (6.7
that won't change TZ
in the parent shell.
The script can set a different
than the parent shell - no problem.
There are times you might want to start a subshell from your current
Maybe you have a special project where you need to work in a
different current directory, reset environment variables,
set a new home directory, reset some aliases, use a different
When you end the subshell, the parent shell's environment will be the way
If your parent shell has
job control (12.1
you can stop the subshell and pop back to your parent shell without losing
the changes in the subshell.
If the child shell has job control, too, the command
(or kill -STOP
) will stop it.
Otherwise, just type CTRL-z at the subshell's prompt.
set prompt="project% "
setenv PRINTER plotter
setenv EXINIT "se ts=4 sw=4 aw wm=0"
...do some work...
...back to parent shell...
...back to subshell...
I use suspend
so much that I've made a CTRL-z-like alias named
shell escape (30.26
starts a subshell.
Do whatever you want to the subshell's environment.
When you end the shell escape, the changes go away.
command starts a subshell.
anywhere, change environment variables, and so on...
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.
explains how exit
sets a shell's exit status.