From Linux Shell Scripting Tutorial - A Beginner's handbook
- The exec command is used to replace the current shell with the command without spawning a new process or subshell.
- The exec command is also used to assign the file descriptor fd to filename:
exec 3> /tmp/output
- The exec command is used by "wrapper" scripts. For example, php-cgi can run as cgi program after setting environment variables or other configuration.
- By using exec, the resources used by the php.cgi shell program do not need to stay in use after the program is started. The following script can be run using Apache web server and it will speed up php execution:
#!/bin/bash # Shell Script wrapper to Run PHP5 using mod_fastcgi under Apache 2.2.x # Tested under CentOS Linux and FreeBSD and 7.x server. PHP_CGI=/usr/local/bin/php-cgi # for centos / rhel set it as follows # PHP_CGI=/usr/bin/php-cgi export PHP_FCGI_CHILDREN=4 export PHP_FCGI_MAX_REQUESTS=1000 exec $PHP_CGI