messaging between a parent and child proccess
Code:
#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
#define BSIZE 100
void parent(int Msgs);
int main()
{
parent(100);
return 0;
}
void parent(int Msgs)
{
int numMsgs = Msgs;
int pid;
int x=0;
int pipe1[2];
int pipe2[2];
char buf[BSIZE];
ssize_t nbytes;
pid = fork();
if(pid < 0)
cout<<"ERROR"<<endl;
else if (pid == 0)
{
close(pipe1[1]);
read(pipe1[0], buf, BSIZE);
cout<<endl;
cout<<"child read"<<endl;
close(pipe2[2]);
}
else
{
close(pipe1[0]);
nbytes = write(pipe1[1], "p", 1);
cout<<endl;
cout<<"parent write"<<endl;
close(pipe1[1]);
cout<<read(pipe2[0], buf, BSIZE);
cout<<endl;
cout<<"parent read"<<endl;
close(pipe2[0]);
//parent code goes here
}
}
//the program has to send messages, the problem i am having is that the message doest not get passed from the parent to the child and back and forth. http://www.cs.stevens-tech.edu/~quyn...1/assign1.html is the link for the exact procedures.