start page | rating of books | rating of authors | reviews | copyrights

Unix Power ToolsUnix Power ToolsSearch this book

27.2. How the Shell Executes Other Commands

When the shell executes an external command (Section 1.9), what happens?

Unix programs are executed through a combination of two system calls (low-level requests to the operating system) called fork and exec.

The exec system call tells the kernel to execute another program. However, the kernel replaces the calling program with the new one being called. This doesn't work too well if you want to return to the original program after the new one has done its job.

To get around this problem, programs that want to stick around first copy themselves with the fork system call. Then the copied program execs the new program, terminating itself in the process.

You don't really need to know this little tidbit about what goes on behind the scenes, but it sure helps to know about fork and exec when reading some Unix manuals. Section 24.2 has more information.

--TOR and SJC



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.