Search
 
SCRIPT & CODE EXAMPLE
 

C

two way communication between child and parent processes in C using pipes

#include <stdio.h>
#include<stdlib.h>
#include 
#include<unistd.h>
int main()
{
    pid_t pid;
    int r;
    char *ch=NULL;
    char *ch1=NULL;
    int readpipe[2];
    int writepipe[2];
    int a;
    int b;
    a=pipe(readpipe);
    b=pipe(writepipe);
      // check a and b

    pid=fork();
    // check pid

    if(pid==0)
    { //CHILD PROCESS
            close(readpipe[1]);
            close(writepipe[1]);
            read(readpipe[0],ch,sizeof(ch));
            printf("
READ = %s",ch);
            close(readpipe[0]);
            ch1="YES";
            write(writepipe[1],ch1,sizeof(ch1));
            close(writepipe[1]);
    }
    else
    { //PARENT PROCESS
            close(writepipe[0]);
            close(writepipe[1]);
            ch="HI!! YOU THERE";
            write(readpipe[1],ch,sizeof(ch));
            close(readpipe[1]);
            read(writepipe[1],ch1,sizeof(ch1));
            printf("
ACK RECEIVED %s",ch1);
            close(writepipe[1]);
    }
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
C :: fungetc 
C :: C Accessing Union Members 
C :: c atoi atof 
C :: columntransformer in randomizedsearchcv 
C :: can we use logical operators in switch c 
C :: do a barrel roll 
C :: c to c convertor 
C :: powershell some fonts like #include are dissapearing 
C :: Answer to storing information in array 
C :: amazon kinesis disaster recovery 
C :: onvert a string into 2d string in c 
C :: scranton inhabitants 
C :: diamond dataset in r 
C :: binary operations on structs C 
C :: perl file handling 
C :: programme c qui permet de determiner si M et N sont amis ou non 
C :: c limit value range 
C :: convert c code to c online 
C :: how to import c data type 
C :: c language dictionary implemet 
C :: c how to include variables of other c file 
C :: read a string 
C :: what to do after gan training 
C :: reverse number in c 
C :: in C char to string 
C :: mark rober 
Dart :: How to create a round CheckBox in Flutter 
Dart :: flutter format currency fcfa 
Dart :: card border radius in flutter 
Dart :: how to make list view non scrollable in flutter 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =