Code:
if(pid == 0)
{
printf("I am the grandchild process %d\n", pid);
/* closes the output side of the pipe */
close(pfd[1]);
/* read input from pipe */
while((test = read(pfd[0], buffer, sizeof(buffer))) != 0)
printf("Testing : %s \n", buffer);
/* closes the input side of the pipe */
close(pfd[0]);
/*test = getc(stdout);
printf("Test : %c", test);*/
_exit(3);
}
if(pid > 0)
{
printf("I am the child process %d\n", pid);
/* closes input side of the pipe */
close(pfd[0]);
/* duplicate pipe output to 1 dup2(int oldfd, int newfd) */
dup2(pfd[1], 1);
/* closes the output side of the pipe */
close(pfd[1]);
/* run the OnOff java program */
execlp("java", "-classpath e:/cpe3007/ass3", "OnOff", (char *) NULL);
/* error message to display if java OnOff fail to execute */
perror("Program OnOff failed to execute \n");
_exit(4);
}
Managed to solve the earlier problem..thanks in advance anyone who look through.
There are few questions I required some assistance though:
Objective: Create a C program taking in one parameter in the name of a mpeg file to run. Another program, a java program is to run as a controller of sort...where when off is pressed, a '0' is output to the stdout and terminated by a newline. This will pause the mpeg file and on will continue movie.
My idea is to create a parent process to run the mpeg file..then create a child process to run the java program and another grandchild to read the input and output to send the signal to the parent process.
Therefore any comments, suggestions are welcome. I have a few questions though.
Q1. Is the code above ok? Primary function is to pipe the output of the java proggie in the parent process into the input of child process.
Q2. Can a grandchild process kill a parent process ??
Thanks again in advance.