This commit is contained in:
2026-04-14 19:12:10 +02:00
parent ddf398dcb6
commit 471fc6d274
+56
View File
@@ -0,0 +1,56 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/types.h>
#include <err.h>
void piped(){
int fd[2];
if(pipe(fd) == -1){
printf("an error occured\n");
return ;
}
pid_t pid = fork();
if(pid < 0){
printf("an error occured\n");
return ;
}
// Child
if (pid == 0) {
close(fd[0]);
char *str = "Hello from your child !\n";
write(fd[1], str, strlen(str) + 1);
close(fd[1]);
exit(0);
}
// Mommy
else {
close(fd[1]);
char buffer[2048];
read(fd[0], buffer, sizeof(buffer));
printf("My child sends me : %s\n", buffer);
close(fd[0]);
wait(NULL);
return;
}
}
int main(){ piped();}