#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
int main()
{
int pipe_fd[2];
pid_t pid1 ;
if (pipe(pipe_fd)==-1)
{
return 1;
}
pid1 = fork();
if (pid1==-1)
{
printf("error creating child process"); }
else if(pid1==0)
{
close(pipe_fd[0]);
int x;
printf("enter a input number : "); write(pipe_fd[1] , &x , sizeof(int));
close(pipe_fd[1]);
}
else
{
close(pipe_fd[1]);
int y;
read(pipe_fd[0] , &y , sizeof(int));
close(pipe_fd[0]);
printf("copied value from child process : %d " , y
);
//wait(NULL);
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzeXMvdHlwZXMuaD4KI2luY2x1ZGUgPHVuaXN0ZC5oPgojaW5jbHVkZSA8c3RkbGliLmg+CiNpbmNsdWRlIDxzeXMvd2FpdC5oPgoKaW50IG1haW4oKQp7CiAgaW50IHBpcGVfZmRbMl07CiAgcGlkX3QgcGlkMSA7CiAgCiAgaWYgKHBpcGUocGlwZV9mZCk9PS0xKQogIHsKICAgIHByaW50ZigiZXJyb3IiKTsKICAgIHJldHVybiAxOwogICAgCiAgfQogIAogIHBpZDEgPSBmb3JrKCk7CiAgaWYgKHBpZDE9PS0xKQogIHsKICAgIHByaW50ZigiZXJyb3IgY3JlYXRpbmcgY2hpbGQgcHJvY2VzcyIpOwogIH0KICAKICBlbHNlIGlmKHBpZDE9PTApCiAgewogICAgY2xvc2UocGlwZV9mZFswXSk7CiAgICBpbnQgeDsKICAgIHByaW50ZigiZW50ZXIgYSBpbnB1dCBudW1iZXIgOiAiKTsKICAgIHNjYW5mKCIlZCIsJngpOwogICAgd3JpdGUocGlwZV9mZFsxXSAsICZ4ICwgc2l6ZW9mKGludCkpOwogICAgY2xvc2UocGlwZV9mZFsxXSk7CiAgfQogIAogIGVsc2UKICB7CiAgICBjbG9zZShwaXBlX2ZkWzFdKTsKICAgIGludCB5OwogICAgCiAgICByZWFkKHBpcGVfZmRbMF0gLCAmeSAsIHNpemVvZihpbnQpKTsKICAgIGNsb3NlKHBpcGVfZmRbMF0pOwogICAgcHJpbnRmKCJjb3BpZWQgdmFsdWUgZnJvbSBjaGlsZCBwcm9jZXNzIDogJWQgIiAsIHkpOwogICAgCiAgICAvL3dhaXQoTlVMTCk7CiAgICAKICB9CiAgICAKICAgIAogICAgCiAgICByZXR1cm4gMDsKfQ==