// this code sample demontrates how to spwan a new process and
// execute a command (shell) in the child process. The parent process
// then will wait until the child's execution is completed
#include <stream.h>
#include <string>
#include <unistd.h>
#include <sys/wait.h>
#define MAXLINE 80
#define WHITE "\t \n"
#define MAXARG 20
typedef char *String;

main() {
  int pid;
//  union wait status;
	int status = 0;
  int i = 0;
  char cmd[MAXLINE];
  String argl[MAXARG];
 
  cout << "enter your command % ";
  cin.getline(cmd, MAXLINE);
 
  // fill in arguments
  argl[i++] = strtok(cmd, WHITE);
  while ( i < MAXARG && 
	  (argl[i++] = strtok(NULL, WHITE)) != NULL); 


  if (fork() == 0) { // the child process
    if (execvp (argl[0], argl) == -1) {
      cerr << "error executing a given command" << endl;
    }
  } 
  else { // the parent process
    pid = wait(&status);  
    cout << "the child's execution is completed" << endl;
  } 
}



