LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-08-2016, 05:45 AM   #1
GTrax
Member
 
Registered: Oct 2005
Location: UK
Distribution: Mint
Posts: 258

Rep: Reputation: 37
Pipes, redirects, nodes, and devices question


Given I was asked the question without having enough Linux knowledge to answer, I try it here.

Is it possible to use a re-direct ">" to send standard output to a device in /dev, while also using a "<" to have incoming standard input from the same device arrive in a file, or maybe program controlled buffer, without needing to install any special kernel modules or devices?

We already know that if we use the "|" pipe command, the outgoing stream is immediately returned to the input stream. For us, the need is to have some sort of node, hopefully a standard device like /dev/TTYn, which can take standard output, and also accept external event input directed into a different buffer.

Thanks for any suggestions.
 
Old 08-09-2016, 09:10 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
If I were going down this path I'd probably look into doing a named pipe setup.

If you do a search for named pipe you can find many hits including this one that may give you ideas:
http://www.linuxjournal.com/content/...pes-fifos-bash
 
Old 08-09-2016, 10:08 AM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
I don't understand the question. You want some device that will read data from stdin and do what with it? You want output from this device to then go to a file, but what output? What is this device doing? What are you sending it and what are you expecting to get out of it?
 
Old 08-10-2016, 08:58 AM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,671
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
The ">" redirect operator transfers one of the process's standard inputs or outputs to/from an external file. Only one process exists.

The "|" pipe operator actually creates two simultaneous processes, and creates a FIFO-queue (a "pipe") which connects the STDOUT of the left-hand process to the STDIN of the right-hand process. Two processes exist, running simultaneously. Eventually the "writer" finishes writing and closes the pipe. The "reader," upon consuming the rest of the information in the pipe, is notified that the pipe has been closed and terminates also.

Pipes provide automatic synchronization and buffering: if the writer writes "too much" and the pipe becomes full, it is suspended until the reader consumes some of it. Likewise, if the reader finds that, at the moment, there's no information there, it is suspended until the writer writes (or, closes the pipe).

Both of these are examples of "redirecting the STDIN, STDOUT, and STDERR streams," but one uses a disk-file while the other uses a pipe.

Also note that, to the user of a pipe, a pipe works just like a (non-seek()-able) disk file.

It really is "quite elegant."

Last edited by sundialsvcs; 08-10-2016 at 09:02 AM.
 
1 members found this post helpful.
Old 08-11-2016, 03:54 AM   #5
GTrax
Member
 
Registered: Oct 2005
Location: UK
Distribution: Mint
Posts: 258

Original Poster
Rep: Reputation: 37
Thanks to all for the replies.

I get it that the ">" redirect always interfaces to a file, which is not what we need.
Clearly the pipe operator is the more useful in this case.

The original sketch showed a program using two FIFO buffers, one for output, another for input, both going to a node which was the interface to the outside world, likely a UDP transfer.

I think the issue was that if an outgoing "|" pipe transfer happened to the node (a device like TTYn ??), then the data was immediately sent back up the other FIFO.

Given there is "automatic" FIFO property inherent in the "|" pipe operator, we may now know enough. Certainly I have learned something new. My colleague is much more skilled at programming than I am, and I have made him aware of this thread.
 
Old 08-11-2016, 06:51 AM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Pipes
Introduction to Pipes
I/O Redirection

Working with Named Pipes
Code:
man tee
Still have this "sketch"?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Learn Linux, 101: Streams, pipes, and redirects LXer Syndicated Linux News 0 05-19-2016 04:13 AM
Setting up Kickstart server RHEL 6.5 for compute nodes, GPU nodes and PHI nodes sho1sho1 Red Hat 3 06-23-2015 04:20 PM
gawk copy files (DOS pipes and redirects) scripterJACK General 6 03-02-2010 11:53 AM
Devices and nodes- Association ?? kewl Linux - Kernel 1 10-01-2009 11:16 AM
devices and pipes siemens Linux - General 1 03-23-2005 03:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration