pipe system call

Solutions on MaxInterview for pipe system call by the best coders in the world

showing results for - "pipe system call"
Santino
23 Jan 2019
1
2#include <stdio.h>
3#include <unistd.h>
4
5int main()
6{
7    int pipeFds[2], status, pId;
8    char writeMsg[20] = "hello world";
9    char readMsg[20];
10
11    status = pipe(pipeFds);
12
13    if (status == -1)
14    {
15        printf("Unable to create pipe\n");
16        return 1;
17    }
18
19    pId = fork();
20
21    // child process
22    if (pId == 0)
23    {
24        read(pipeFds[0], readMsg, sizeof(readMsg));
25        printf("\nChild Process receives data\n%s\n", readMsg);
26    }
27    // parent process
28    else if (pId > 0)
29    {
30        printf("Parent Process sends data\n%s", writeMsg);
31        write(pipeFds[1], writeMsg, sizeof(writeMsg));
32    }
33
34    return 0;
35}
similar questions
how to read write in pipe