Skip to content

Instantly share code, notes, and snippets.

@morsoinferno
Created March 31, 2017 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morsoinferno/53334a6721d937c86b162683aeb55222 to your computer and use it in GitHub Desktop.
Save morsoinferno/53334a6721d937c86b162683aeb55222 to your computer and use it in GitHub Desktop.
03_pipe1
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
void main()
{
int fd[2];
int msg_length;
char msg[100];
if (pipe(fd) == -1)
{
perror("No se pudo crear el pipe");
exit(-1);
}
printf("Descriptor fd[0] = %d\n", fd[0]);
printf("Descriptor fd[1] = %d\n", fd[1]);
if (write(fd[1], "Hola pipe\n", 10) != 10)
{
printf("No se pudo escribir en el pipe");
exit(-1);
}
if ((msg_length = read(fd[0], msg, sizeof(msg))) <= 0)
{
printf("No se pudo leer del pipe");
exit(-1);
}
if (write(1, msg , msg_length) != msg_length)
{
printf("No se pudo escribir mensaje");
exit(-1);
}
exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment