我有一个父程序向子程序发送一个整数,子程序将该数字乘以 2 并返回给父程序。
在主程序中,我创建了一个管道和 fork() 和 execl() 子程序,在切换后我通过 pip 将值传递给子程序中的子程序,我可以获得该值,但是如何从子程序中获取结果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;
}
}