// C program for Linux to spawn child process
//   Command line arguments:
//     Full Path to Executable egs. Linux ... `which ls` or /bin/ls
//     Usual Other Command Line Arguments relevant to executable above
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>

#define MAX_LENGTH 501

int main(int argc,char** argv){
    int status;
    char argvone[MAX_LENGTH] = ".\0";
    pid_t pid;
    int i, k=0;
    if (argc > 1) {
      for (i=1; i<argc; i++)
      {
          if (strlen(argvone) == 1) {
              strcpy(argvone, argv[i]);
          } else if (k == 0) {
              k = i;
          }
      }
      if ((pid = fork()) == -1) {
          perror("Error with fork.");
      } else if (pid == 0) {
          execv(argvone, (argv+k));
          _exit(0);
      } else {
          wait(&status);
      }
    }
    return 0;
}
