delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2000/12/15/10:44:45

X-Authentication-Warning: kendall.sfbr.org: jeffw set sender to jeffw AT darwin DOT sfbr DOT org using -f
Date: Fri, 15 Dec 2000 09:46:17 -0600
From: JT Williams <jeffw AT darwin DOT sfbr DOT org>
To: djgpp-workers AT delorie DOT com
Subject: purpose of fork() in GNU time 1.7
Message-ID: <20001215094617.A23499@kendall.sfbr.org>
Mail-Followup-To: djgpp-workers AT delorie DOT com
Mime-Version: 1.0
User-Agent: Mutt/1.3.12i
Reply-To: djgpp-workers AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019