From: Carl Edquist <edquist@cs.wisc.edu>
To: Chet Ramey <chet.ramey@case.edu>
Cc: Zachary Santer <zsanter@gmail.com>, bug-bash <bug-bash@gnu.org>,
libc-alpha@sourceware.org
Subject: Re: Examples of concurrent coproc usage?
Date: Sat, 20 Apr 2024 17:04:27 -0500 (CDT) [thread overview]
Message-ID: <2febc4ce-a9a8-d1a9-51c3-0ed5d1b20716@cs.wisc.edu> (raw)
In-Reply-To: <bbfa18b9-4c28-46e7-833b-6861535b8a64@case.edu>
On Wed, 17 Apr 2024, Chet Ramey wrote:
> On 4/15/24 1:01 PM, Carl Edquist wrote:
>>
>> Yet another point brought to light by the bcalc example relates to the
>> coproc pid variable. The reset() function first closes the coproc
>> pipe fds, then sleeps for a second to give the BC coproc some time to
>> finish.
>>
>> An alternative might be to 'wait' for the coproc to finish (likely
>> faster than sleeping for a second).
>
> If the coproc has some problem and doesn't exit immediately, `wait'
> without options will hang. That's why I opted for the
> sleep/kill-as-insurance combo.
Yes that much was clear from the script itself.
I didn't mean any of that as a critique of the bcalc script. I just meant
it brought to light the point that the coproc pid variable is another
thing in the current deallocate-on-terminate behavior, that needs to be
copied before it can be used reliably. (With the 'kill' or 'wait'
builtins.)
Though I do suspect that the most common case with coprocs is that closing
the shell's read and write fds to the coproc is enough to cause the coproc
to finish promptly - as neither read attempts on its stdin nor write
attempts on its stdout can block anymore.
I think this is _definitely_ true for the BC coproc in the bcalc example.
But it's kind of a distraction to get hung up on that detail, because in
the general case there may very well be other scenarios where it would be
appropriate to, um, _nudge_ the coproc a bit with the kill command.
> (And before you ask why I didn't use `wait -n', I wrote bcalc in 30
> minutes after someone asked me a question about doing floating point
> math with awk in a shell script, and it worked.)
It's fine! It's just an example, after all :)
Carl
next prev parent reply other threads:[~2024-04-20 22:03 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CABkLJULa8c0zr1BkzWLTpAxHBcpb15Xms0-Q2OOVCHiAHuL0uA@mail.gmail.com>
[not found] ` <9831afe6-958a-fbd3-9434-05dd0c9b602a@draigBrady.com>
2024-03-10 15:29 ` RFE: enable buffering on null-terminated data Zachary Santer
2024-03-10 20:36 ` Carl Edquist
2024-03-11 3:48 ` Zachary Santer
2024-03-11 11:54 ` Carl Edquist
2024-03-11 15:12 ` Examples of concurrent coproc usage? Zachary Santer
2024-03-14 9:58 ` Carl Edquist
2024-03-17 19:40 ` Zachary Santer
2024-04-01 19:24 ` Chet Ramey
2024-04-01 19:31 ` Chet Ramey
2024-04-02 16:22 ` Carl Edquist
2024-04-03 13:54 ` Chet Ramey
2024-04-03 14:32 ` Chet Ramey
2024-04-03 17:19 ` Zachary Santer
2024-04-08 15:07 ` Chet Ramey
2024-04-09 3:44 ` Zachary Santer
2024-04-13 18:45 ` Chet Ramey
2024-04-14 2:09 ` Zachary Santer
2024-04-04 12:52 ` Carl Edquist
2024-04-04 23:23 ` Martin D Kealey
2024-04-08 19:50 ` Chet Ramey
2024-04-09 14:46 ` Zachary Santer
2024-04-13 18:51 ` Chet Ramey
2024-04-09 15:58 ` Carl Edquist
2024-04-13 20:10 ` Chet Ramey
2024-04-14 18:43 ` Zachary Santer
2024-04-15 18:55 ` Chet Ramey
2024-04-15 17:01 ` Carl Edquist
2024-04-17 14:20 ` Chet Ramey
2024-04-20 22:04 ` Carl Edquist [this message]
2024-04-22 16:06 ` Chet Ramey
2024-04-27 16:56 ` Carl Edquist
2024-04-28 17:50 ` Chet Ramey
2024-04-08 16:21 ` Chet Ramey
2024-04-12 16:49 ` Carl Edquist
2024-04-16 15:48 ` Chet Ramey
2024-04-20 23:11 ` Carl Edquist
2024-04-22 16:12 ` Chet Ramey
2024-04-17 14:37 ` Chet Ramey
2024-04-20 22:04 ` Carl Edquist
2024-03-12 3:34 ` RFE: enable buffering on null-terminated data Zachary Santer
2024-03-14 14:15 ` Carl Edquist
2024-03-18 0:12 ` Zachary Santer
2024-03-19 5:24 ` Kaz Kylheku
2024-03-19 12:50 ` Zachary Santer
2024-03-20 8:55 ` Carl Edquist
2024-04-19 0:16 ` Modify buffering of standard streams via environment variables (not LD_PRELOAD)? Zachary Santer
2024-04-19 9:32 ` Pádraig Brady
2024-04-19 11:36 ` Zachary Santer
2024-04-19 12:26 ` Pádraig Brady
2024-04-19 16:11 ` Zachary Santer
2024-04-20 16:00 ` Carl Edquist
2024-04-20 20:00 ` Zachary Santer
2024-04-20 21:45 ` Carl Edquist
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/libc/involved.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2febc4ce-a9a8-d1a9-51c3-0ed5d1b20716@cs.wisc.edu \
--to=edquist@cs.wisc.edu \
--cc=bug-bash@gnu.org \
--cc=chet.ramey@case.edu \
--cc=libc-alpha@sourceware.org \
--cc=zsanter@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).