Introducing UNIX and Linux |
Advanced shell programmingOverview |
The 'exec' mechanismWhen you execute a script, a copy of the shell is created. Thus
when that script itself executes a command, a process is created
for that command as well as the process for the calling shell. This
is potentially inefficient, especially if the script is relatively
simple, but essentially unavoidable. In a few instances, however,
the calling shell is redundant, in particular if a utility is
executed as the last command in the shell. The shell will terminate
precisely when the utility has terminated. During the time that the
utility is running, the shell's process continues to run, but is
simply waiting for the utility to finish - nothing more. This is
inefficient because the kernel still needs to manage the shell
process, and the shell is a 'big' program. The command
There are 4 processes, your login shell
The shell script was created with PID Worked exampleWrite a script to take one argument, assumed to be a filename,
and run # Check number of arguments if [ $# -ne 1 ] # If too few arguments, warn user then echo $0 requires exactly 1 argument # and exit with status 1 exit 1 # otherwise run vi else exec vi $1 fi |
Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck