pipes.c

PHOTO EMBED

Wed May 08 2024 09:38:17 GMT+0000 (Coordinated Universal Time)

Saved by @login123

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int fd[2];
    char string[] = "welcome", b[80];
    pipe(fd);
    if (fork() == 0) {
        write(fd[1], string, strlen(string));
    } else {
        read(fd[0], b, sizeof(b));
        printf("received string: %s\n", b);
    }
    return 0;
}
content_copyCOPY