I have a parent program that sends a integer to a child, and the child program multiplies the number by two and gives back to the parent.
In a main program I create a pipe and fork() and execl() the child, after a switch I pass the value through pip to child in child i can get the value, but How can I get a result back from the child to the parent after a execl()?.
child.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(){
int fd,nread,result;
char data[20];
fd=atoi(argv[1]);
nread=read(fd,data,sizeof(data));
switch(nread)
{
case -1:
break;
default:
result=atoi(data)*2;
sprintf(result,"%d",(result));
//how can here return data to the parent?
break;
}
}