how to use unkown pipes ?

in this code i am tryin to pass the Id to the child process but it doesot work .i think the problem is in wich pipe to close .


file : racine.pp

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <iostream>
#include <fstream>
#include <string.h>
#include <sstream>
#define R 0
#define W 1

int P2fils1[2];
int f2pere1[2];

void addprocess()
{
char x[10];
int Id = 11;

char msg= "the child id is 11 ";
pipe(P2fils1);
int pid = fork();
if(pid == 0)
{
close(f2pere1[W]);
sprintf(x,"%d\n",P2fils1[R]);
execl("./fils", "./fils",x, NULL);
}
else
{
close(P2fils1[W]);
}
read(P2fils1[R], &msg, sizeof(int));
close(P2fils1[R]);

file fils.cpp

int main (int argc, char *argv[])
{


int msg = 2;
pipeRacineToMe = atoi(argv[1]);
write(pipeRacineToMe, &msg, sizeof(int));
cout << pipeRacineToMe;
close(atoi(argv[2]));
}

Last edited on
Both the parent and the child close the write side of the pipe. You want the child to close
the read side instead.
Topic archived. No new replies allowed.