Mail Archives: djgpp-workers/2000/12/15/10:44:45
Could someone please explain the following section of code from GNU
time-1.7? What is the purpose of the `fork()' call when the command
to be timed is later run by the `execvp' procedure? Won't the rusage
structure get updated just as well without the fork()?
TIA/jtw
------
pid = fork (); /* Run CMD as child process. */
if (pid < 0)
error (1, errno, "cannot fork");
else if (pid == 0)
{ /* If child. */
/* Don't cast execvp arguments; that causes errors on some systems,
versus merely warnings if the cast is left off. */
execvp (cmd[0], cmd);
error (0, errno, "cannot run %s", cmd[0]);
_exit (errno == ENOENT ? 127 : 126);
}
- Raw text -