text: /*************************************************************************\
  *                  Copyright (C) Michael Kerrisk, 2018.                   *
  *                                                                         *
  * This program is free software. You may use, modify, and redistribute it *
  * under the terms of the GNU General Public License as published by the   *
  * Free Software Foundation, either version 3 or (at your option) any      *
  * later version. This program is distributed without any warranty.  See   *
  * the file COPYING.gpl-v3 for details.                                    *
  \*************************************************************************/
  
  /* Listing 27-8 */
  
  /* simple_system.c
  
     A simple implementation of system(3) that excludes signal manipulation.
  
     See also system.c.
  */
  #include <unistd.h>
  #include <sys/wait.h>
  #include <sys/types.h>
  
  int
  system(char *command)
  {
      int status;
      pid_t childPid;
  
      switch (childPid = fork()) {
      case -1: /* Error */
          return -1;
  
      case 0: /* Child */
          execl("/bin/sh", "sh", "-c", command, (char *) NULL);
          _exit(127);                     /* Failed exec */
  
      default: /* Parent */
          if (waitpid(childPid, &status, 0) == -1)
              return -1;
          else
              return status;
      }
  }
  