#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int numbytes;
int fd[2];
pid_t pid;
char line[1024];
if (pipe(fd) < 0)
{
printf("Pipe Error");
exit(0);
}
if ((pid = fork()) < 0)
{
printf("Fork Error");
exit(0);
}
else if (pid > 0) /* parent */
{
close(fd[0]);
write(fd[1], "Howdy\n", 6);
}
else /* child */
{
close(fd[1]);
numbytes = read(fd[0], line,1024);
write(STDOUT_FILENO, line, numbytes);
}
exit(0);
}
Master programming effortlessly with Simplest Codings. From core algorithms and LLMs to clean code in Java, C++, and Python—get clear, bite-sized tutorials and practical developer guides for all skill levels.
Monday, August 9, 2010
Pipe from parent to child
This is a simple example of sending data over a pipe in Unix/Linux , from parent to child.
Subscribe to:
Post Comments (Atom)
-
Overview of the SSL handshake Courtesy: http://www-01.ibm.com/support/knowledgecenter Steps involved in SSL handshake (Courtesy:...
-
To implement the kind of storage which stores strings as the search keys , there is a need to have special data structures which can store ...
-
A simple implementation of a packet sniffer in C on linux platform using the libpcap library. This packet sniffer currently sniffs IP , TCP ...
No comments:
Post a Comment
Please post your valuable suggestions