Is coproc the same as &?
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I have read that $coproc < command >
is different from $< command > &
in that coproc
will execute command
in a sub-shell process.
But when I tested it, it worked just like $< command > &
. The test is as follow:
First: test the behavior of $< command > &
.
- Run
$nano &
on tty1 - On another tty, output from
$ps -t tty1 --forest
indicates nano process is child process of the -bash process (login bash shell process -> no sub-shell process was created)
Second: test the behavior of $coproc < command >
- Run
$coproc nano
on tty1 - On another tty, output from
$ps -t tty1 --forest
is the same as above (no sub-shell process was created)
So is $coproc < command >
simply the same as $< command > &
?
The shell used was a bash shell
bash coprocesses
add a comment |Â
up vote
2
down vote
favorite
I have read that $coproc < command >
is different from $< command > &
in that coproc
will execute command
in a sub-shell process.
But when I tested it, it worked just like $< command > &
. The test is as follow:
First: test the behavior of $< command > &
.
- Run
$nano &
on tty1 - On another tty, output from
$ps -t tty1 --forest
indicates nano process is child process of the -bash process (login bash shell process -> no sub-shell process was created)
Second: test the behavior of $coproc < command >
- Run
$coproc nano
on tty1 - On another tty, output from
$ps -t tty1 --forest
is the same as above (no sub-shell process was created)
So is $coproc < command >
simply the same as $< command > &
?
The shell used was a bash shell
bash coprocesses
Possible duplicate of How do you use the command coproc in various shells?
– Stéphane Chazelas
13 mins ago
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have read that $coproc < command >
is different from $< command > &
in that coproc
will execute command
in a sub-shell process.
But when I tested it, it worked just like $< command > &
. The test is as follow:
First: test the behavior of $< command > &
.
- Run
$nano &
on tty1 - On another tty, output from
$ps -t tty1 --forest
indicates nano process is child process of the -bash process (login bash shell process -> no sub-shell process was created)
Second: test the behavior of $coproc < command >
- Run
$coproc nano
on tty1 - On another tty, output from
$ps -t tty1 --forest
is the same as above (no sub-shell process was created)
So is $coproc < command >
simply the same as $< command > &
?
The shell used was a bash shell
bash coprocesses
I have read that $coproc < command >
is different from $< command > &
in that coproc
will execute command
in a sub-shell process.
But when I tested it, it worked just like $< command > &
. The test is as follow:
First: test the behavior of $< command > &
.
- Run
$nano &
on tty1 - On another tty, output from
$ps -t tty1 --forest
indicates nano process is child process of the -bash process (login bash shell process -> no sub-shell process was created)
Second: test the behavior of $coproc < command >
- Run
$coproc nano
on tty1 - On another tty, output from
$ps -t tty1 --forest
is the same as above (no sub-shell process was created)
So is $coproc < command >
simply the same as $< command > &
?
The shell used was a bash shell
bash coprocesses
bash coprocesses
asked 1 hour ago


Tran Triet
748
748
Possible duplicate of How do you use the command coproc in various shells?
– Stéphane Chazelas
13 mins ago
add a comment |Â
Possible duplicate of How do you use the command coproc in various shells?
– Stéphane Chazelas
13 mins ago
Possible duplicate of How do you use the command coproc in various shells?
– Stéphane Chazelas
13 mins ago
Possible duplicate of How do you use the command coproc in various shells?
– Stéphane Chazelas
13 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
coproc utility
is not the same as utility &
in bash
.
With coproc utility
you get an array, COPROC
, that contains the standard input and output filedescriptors of utility
. You may then do things like
#!/bin/bash
coproc bc -l
for (( k = 0; k < 50; ++k )); do
printf "2.3*%d + 1n" "$k" >&$COPROC[1]
read -u "$COPROC[0]" a
printf '%.2fn' "$a"
done
kill "$COPROC_PID"
Here, bc -l
is a co-process and acts like a "arithmetic computation service" for the shell loop, taking expressions to compute on its standard input and giving back results on its standard output.
As far as I can tell, bash
also only supports one co-process at any one time. The ksh93
shell also supports co-processes, but the syntax is totally different (but somewhat sleeker).
add a comment |Â
up vote
0
down vote
The difference is the creation of two I/O channels, as described in man bash
:
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.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
coproc utility
is not the same as utility &
in bash
.
With coproc utility
you get an array, COPROC
, that contains the standard input and output filedescriptors of utility
. You may then do things like
#!/bin/bash
coproc bc -l
for (( k = 0; k < 50; ++k )); do
printf "2.3*%d + 1n" "$k" >&$COPROC[1]
read -u "$COPROC[0]" a
printf '%.2fn' "$a"
done
kill "$COPROC_PID"
Here, bc -l
is a co-process and acts like a "arithmetic computation service" for the shell loop, taking expressions to compute on its standard input and giving back results on its standard output.
As far as I can tell, bash
also only supports one co-process at any one time. The ksh93
shell also supports co-processes, but the syntax is totally different (but somewhat sleeker).
add a comment |Â
up vote
2
down vote
coproc utility
is not the same as utility &
in bash
.
With coproc utility
you get an array, COPROC
, that contains the standard input and output filedescriptors of utility
. You may then do things like
#!/bin/bash
coproc bc -l
for (( k = 0; k < 50; ++k )); do
printf "2.3*%d + 1n" "$k" >&$COPROC[1]
read -u "$COPROC[0]" a
printf '%.2fn' "$a"
done
kill "$COPROC_PID"
Here, bc -l
is a co-process and acts like a "arithmetic computation service" for the shell loop, taking expressions to compute on its standard input and giving back results on its standard output.
As far as I can tell, bash
also only supports one co-process at any one time. The ksh93
shell also supports co-processes, but the syntax is totally different (but somewhat sleeker).
add a comment |Â
up vote
2
down vote
up vote
2
down vote
coproc utility
is not the same as utility &
in bash
.
With coproc utility
you get an array, COPROC
, that contains the standard input and output filedescriptors of utility
. You may then do things like
#!/bin/bash
coproc bc -l
for (( k = 0; k < 50; ++k )); do
printf "2.3*%d + 1n" "$k" >&$COPROC[1]
read -u "$COPROC[0]" a
printf '%.2fn' "$a"
done
kill "$COPROC_PID"
Here, bc -l
is a co-process and acts like a "arithmetic computation service" for the shell loop, taking expressions to compute on its standard input and giving back results on its standard output.
As far as I can tell, bash
also only supports one co-process at any one time. The ksh93
shell also supports co-processes, but the syntax is totally different (but somewhat sleeker).
coproc utility
is not the same as utility &
in bash
.
With coproc utility
you get an array, COPROC
, that contains the standard input and output filedescriptors of utility
. You may then do things like
#!/bin/bash
coproc bc -l
for (( k = 0; k < 50; ++k )); do
printf "2.3*%d + 1n" "$k" >&$COPROC[1]
read -u "$COPROC[0]" a
printf '%.2fn' "$a"
done
kill "$COPROC_PID"
Here, bc -l
is a co-process and acts like a "arithmetic computation service" for the shell loop, taking expressions to compute on its standard input and giving back results on its standard output.
As far as I can tell, bash
also only supports one co-process at any one time. The ksh93
shell also supports co-processes, but the syntax is totally different (but somewhat sleeker).
edited 10 mins ago
answered 16 mins ago


Kusalananda
107k14209331
107k14209331
add a comment |Â
add a comment |Â
up vote
0
down vote
The difference is the creation of two I/O channels, as described in man bash
:
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.
add a comment |Â
up vote
0
down vote
The difference is the creation of two I/O channels, as described in man bash
:
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.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
The difference is the creation of two I/O channels, as described in man bash
:
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.
The difference is the creation of two I/O channels, as described in man bash
:
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.
answered 1 hour ago
RudiC
1,5979
1,5979
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f472561%2fis-coproc-command-the-same-as-command%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Possible duplicate of How do you use the command coproc in various shells?
– Stéphane Chazelas
13 mins ago