#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <iostream>
#include <signal.h>

//CSE 660
//Jason Kim

using namespace std;

int main()
{
	int pidd;
	pidd = getpid();
	cout << "Process D starting with pid of " << pidd << endl;
	int y,z,x;
	

	char *arg[1]={0};
	char *arg2[0];

	
	y=fork();
	
	if(y==0)
	{
		execv("CC.o",arg);//process C3
		
	}
	sleep(4); // wait  4 seconds
	
	z=fork();
	if(z==0)
	{	
		cout << "process hostname starting" << endl;
		cout << "hostname: ";
		execv("/bin/hostname",arg2); //runs hostname
	}
	sleep(1);
	x=fork();
	if(x==0)
	{
		cout << "process ps starting" << endl;
		execv("/bin/ps",arg); //runs ps
		
	}
	sleep(5); //wait 5 sec
	
	cout << "Process D - Terminating Process C3" << endl;
	kill(y,9);
	cout << "Process D Terminating" << endl;
	exit(1);
	return 0;
}

