Giter Club home page Giter Club logo

ipc-fdstream's Introduction

This is a basic example of inter-process communication
using fork() and pipe() in C++

Includes an example of creating a C++ stream from a file descriptor
and how to read/write from/to it using << and >> operators

Needs GCC's libstdc++ and a POSIX environment

Usage:
	$ make
	$ ./parent

Output:
	Parent: I'll send the child a message.
	Parent: Child just said through stdout:
		"Program: I've received: 'Hello Child!'"
	Parent: Child just said through stderr:
		"Program: This is the error stream!"


The scenario is: A parent process wants to handle another program’s
input and output streams, a process-level wrapper.

So the example is: A parent process forks into another child
process. The parent sends the child a message, the child receives it
and outputs it to the parent to show the communication works just
fine.

The forked process calls the program we want to control. Which in this
case is the easiest C++ program ever: Just reads a line from the
standard input and outputs a message containing the line just read
through the standard output. In addition, another message is sent
through the standard error stream.

Further explanation:
https://blog.eldruin.com/inter-process-communication-pipe-fork-cpp-stl-like-streams/

Resources:
     YoLinux Tutorial: Fork, Exec and Process control
     Beginning Linux programming, Matthew & Stones, Wrox Press
     The GNU C Library manual
     The GNU C++ Library manual
     fileno(3) on C++ Streams: A Hacker's Lament, Richard B. Kreckel


Author: Diego Barrios Romero
Public domain Copyleft 2011

ipc-fdstream's People

Contributors

eldruin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.