LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-10-2022, 09:04 AM   #1
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 369
Blog Entries: 1

Rep: Reputation: 49
Difference between bash coproc and pipes


Dear LQ,

From the little I read on bash's coproc, they just seem to be serving the same
purpose as pipes, that is, giving you a means to read form a program and write
to it, the only exception here is that the communication can be bidirectionnal,
whereas in a pipe the left part only writes to the right part, and the right
part only reads from the left part.

Is there any other thing I am missing from coprocs ? can they be defined as
bidirectional pipes ?
 
Old 02-10-2022, 09:17 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,041

Rep: Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348
Quote:
A coprocess is a shell command preceded by the coproc reserved word. A coprocess is executed asynchronously in a subshell, as if the command had been terminated with the ‘&’ control operator, with a two-way pipe established between the executing shell and the coprocess.
with other words:
Quote:
coproc command in Linux is a shell command which allows us to create a co-process that is connected to the invoking shell via two pipes.
And
Quote:
A pipe is a form of redirection (transfer of standard output to some other destination) that is used in Linux and other Unix-like operating systems to send the output of one command/program/process to another command/program/process for further processing. ... You can make it do so by using the pipe character '|'.
pipe is just a redirection operator, but shell needs to create a co-proc (or two) to make it work. So yes, they are similar to each other, but not the same.
 
1 members found this post helpful.
Old 02-10-2022, 09:24 AM   #3
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

Rep: Reputation: Disabled
I can see how using coprocesses may be more convenient than using named pipes and multiple redirections.

Last edited by shruggy; 02-10-2022 at 09:51 AM.
 
Old 02-10-2022, 12:01 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,691
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
In Linux/Unix, a "pipe" appears to be a file. You can read from it or write to it. What it actually is, though, is a unidirectional queue. A process that reads from it will be blocked until data arrives. A process that writes to it will be blocked if it has become full. It can be named or anonymous.
 
  


Reply

Tags
bash, bash coproc



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Investigating Some Unexpected Bash coproc Behavior LXer Syndicated Linux News 0 09-20-2018 02:10 PM
LXer: An introduction to pipes and named pipes in Linux LXer Syndicated Linux News 0 08-23-2018 06:01 PM
[SOLVED] Bash - Capture "Child" script output with "Parent" without using files or coproc keyword Jason_25 Programming 2 02-14-2016 07:51 PM
Use of coproc in bash - an example, not a problem. PTrenholme Programming 12 12-17-2013 03:54 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:15 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