ksh.1: Mention Co-processes in $!

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

ksh.1: Mention Co-processes in $!

Klemens Nanni-2
Otherwise it is not clear whether $! will be set or not.  This way,
`/Co-proc<enter>' brings me to *all* relevant spots in the manual.

Snippet to demonstrate how $! is set for an asynchronous process:

        $ ksh -c ': |& echo $!'
        67163

FWIW, sh(1) doesn't document Co-processes (whis is fine/correct) and
bash(1) says this about $!:

        !      Expands to the process ID of the job most recently placed into
               the background, whether executed as an asynchronous command or
               using the bg builtin (see JOB CONTROL below).

Feedback? OK?


Index: ksh.1
===================================================================
RCS file: /cvs/src/bin/ksh/ksh.1,v
retrieving revision 1.209
diff -u -p -r1.209 ksh.1
--- ksh.1 7 Jul 2020 10:33:58 -0000 1.209
+++ ksh.1 1 Aug 2020 15:50:04 -0000
@@ -1247,8 +1247,9 @@ The following special parameters are imp
 set directly using assignments:
 .Bl -tag -width "1 ... 9"
 .It Ev \&!
-Process ID of the last background process started.
-If no background processes have been started, the parameter is not set.
+Process ID of the last background process or asynchronous process (Co-process)
+started.
+If no processes have been started, the parameter is not set.
 .It Ev \&#
 The number of positional parameters ($1, $2, etc.).
 .It Ev \&$

Reply | Threaded
Open this post in threaded view
|

Re: ksh.1: Mention Co-processes in $!

Jason McIntyre-2
On Sat, Aug 01, 2020 at 05:57:01PM +0200, Klemens Nanni wrote:

> Otherwise it is not clear whether $! will be set or not.  This way,
> `/Co-proc<enter>' brings me to *all* relevant spots in the manual.
>
> Snippet to demonstrate how $! is set for an asynchronous process:
>
> $ ksh -c ': |& echo $!'
> 67163
>
> FWIW, sh(1) doesn't document Co-processes (whis is fine/correct) and
> bash(1) says this about $!:
>
> !      Expands to the process ID of the job most recently placed into
>       the background, whether executed as an asynchronous command or
>       using the bg builtin (see JOB CONTROL below).
>
> Feedback? OK?
>
>
> Index: ksh.1
> ===================================================================
> RCS file: /cvs/src/bin/ksh/ksh.1,v
> retrieving revision 1.209
> diff -u -p -r1.209 ksh.1
> --- ksh.1 7 Jul 2020 10:33:58 -0000 1.209
> +++ ksh.1 1 Aug 2020 15:50:04 -0000
> @@ -1247,8 +1247,9 @@ The following special parameters are imp
>  set directly using assignments:
>  .Bl -tag -width "1 ... 9"
>  .It Ev \&!
> -Process ID of the last background process started.
> -If no background processes have been started, the parameter is not set.
> +Process ID of the last background process or asynchronous process (Co-process)
> +started.
> +If no processes have been started, the parameter is not set.
>  .It Ev \&#
>  The number of positional parameters ($1, $2, etc.).
>  .It Ev \&$
>

hi/

i'm worried that you're blurring the distinction between asynchronous
and co-process for the reader. i think that's relevant because, as you
say, a page like sh(1) does not document co-processes, whereas ksh(1)
does.

as i understand it, ksh explains co-processes as a type of asynchronous
process. and the setting of "!" is applicable to both. is that right?

so could your text be better written as:

        Process ID of the last background or asynchronous process started.
        If no processes have been started, the parameter is not set.

this would catch the setting of "!" for both async and co-process,
without making the text read like the two are identical.

if your concern is that you need to be able to /co-process, then i'd
rewrite the text to not blur the two:

        Process ID of the last background, co-process, or asynchronous
        process started.

but i dislike that, because it means the text suffers because of an
arbitrary request to make a specific search work.

i guess we could add a note to the "Some notes concerning co-processes"
section if it needs more clarity.

what do you think?

jmc

Reply | Threaded
Open this post in threaded view
|

Re: ksh.1: Mention Co-processes in $!

Klemens Nanni-2
On Sat, Aug 01, 2020 at 05:40:07PM +0100, Jason McIntyre wrote:
> i'm worried that you're blurring the distinction between asynchronous
> and co-process for the reader. i think that's relevant because, as you
> say, a page like sh(1) does not document co-processes, whereas ksh(1)
> does.
You raise a valid point.

> as i understand it, ksh explains co-processes as a type of asynchronous
> process. and the setting of "!" is applicable to both. is that right?
Correct.  Both background jobs (`&') and co-processes (`|&') are
asynchronous and co-processes are background jobs by definition.

What makes co-processes different is a two-way pipe between them and
the shell, i.e. you can read and write in both directions.

> so could your text be better written as:
>
> Process ID of the last background or asynchronous process started.
> If no processes have been started, the parameter is not set.
>
> this would catch the setting of "!" for both async and co-process,
> without making the text read like the two are identical.
>
> if your concern is that you need to be able to /co-process, then i'd
> rewrite the text to not blur the two:
>
> Process ID of the last background, co-process, or asynchronous
> process started.
>
> but i dislike that, because it means the text suffers because of an
> arbitrary request to make a specific search work.
Indeed, I'd like to have `/co-process<enter>' show it.

> i guess we could add a note to the "Some notes concerning co-processes"
> section if it needs more clarity.
I don't think this is needed.

Background jobs as well as co-processes are async and background jobs or
rather `&' is documented as "asynchronous command" in other places of
the manual, so how about this?


Index: ksh.1
===================================================================
RCS file: /cvs/src/bin/ksh/ksh.1,v
retrieving revision 1.209
diff -u -p -r1.209 ksh.1
--- ksh.1 7 Jul 2020 10:33:58 -0000 1.209
+++ ksh.1 1 Aug 2020 16:59:10 -0000
@@ -1247,8 +1247,8 @@ The following special parameters are imp
 set directly using assignments:
 .Bl -tag -width "1 ... 9"
 .It Ev \&!
-Process ID of the last background process started.
-If no background processes have been started, the parameter is not set.
+Process ID of the last background process or co-process started.
+If no asynchronous processes have been started, the parameter is not set.
 .It Ev \&#
 The number of positional parameters ($1, $2, etc.).
 .It Ev \&$

Reply | Threaded
Open this post in threaded view
|

Re: ksh.1: Mention Co-processes in $!

Jason McIntyre-2
On Sat, Aug 01, 2020 at 06:59:43PM +0200, Klemens Nanni wrote:

> On Sat, Aug 01, 2020 at 05:40:07PM +0100, Jason McIntyre wrote:
> > i'm worried that you're blurring the distinction between asynchronous
> > and co-process for the reader. i think that's relevant because, as you
> > say, a page like sh(1) does not document co-processes, whereas ksh(1)
> > does.
> You raise a valid point.
>
> > as i understand it, ksh explains co-processes as a type of asynchronous
> > process. and the setting of "!" is applicable to both. is that right?
> Correct.  Both background jobs (`&') and co-processes (`|&') are
> asynchronous and co-processes are background jobs by definition.
>
> What makes co-processes different is a two-way pipe between them and
> the shell, i.e. you can read and write in both directions.
>
> > so could your text be better written as:
> >
> > Process ID of the last background or asynchronous process started.
> > If no processes have been started, the parameter is not set.
> >
> > this would catch the setting of "!" for both async and co-process,
> > without making the text read like the two are identical.
> >
> > if your concern is that you need to be able to /co-process, then i'd
> > rewrite the text to not blur the two:
> >
> > Process ID of the last background, co-process, or asynchronous
> > process started.
> >
> > but i dislike that, because it means the text suffers because of an
> > arbitrary request to make a specific search work.
> Indeed, I'd like to have `/co-process<enter>' show it.
>
> > i guess we could add a note to the "Some notes concerning co-processes"
> > section if it needs more clarity.
> I don't think this is needed.
>
> Background jobs as well as co-processes are async and background jobs or
> rather `&' is documented as "asynchronous command" in other places of
> the manual, so how about this?
>

hmm. so then the current text ("the last background process") already
covers all these cases. why single out co-processes?

for the reader, i think the idea of background is easier to understand
as an umberella term, rather than asynchronous, even if it's maybe not
so correct.

either you or i have trimmed your original mail, explaining why
this was important ;)

jmc

>
> Index: ksh.1
> ===================================================================
> RCS file: /cvs/src/bin/ksh/ksh.1,v
> retrieving revision 1.209
> diff -u -p -r1.209 ksh.1
> --- ksh.1 7 Jul 2020 10:33:58 -0000 1.209
> +++ ksh.1 1 Aug 2020 16:59:10 -0000
> @@ -1247,8 +1247,8 @@ The following special parameters are imp
>  set directly using assignments:
>  .Bl -tag -width "1 ... 9"
>  .It Ev \&!
> -Process ID of the last background process started.
> -If no background processes have been started, the parameter is not set.
> +Process ID of the last background process or co-process started.
> +If no asynchronous processes have been started, the parameter is not set.
>  .It Ev \&#
>  The number of positional parameters ($1, $2, etc.).
>  .It Ev \&$
>

Reply | Threaded
Open this post in threaded view
|

Re: ksh.1: Mention Co-processes in $!

Klemens Nanni-2
On Sat, Aug 01, 2020 at 06:06:32PM +0100, Jason McIntyre wrote:
> hmm. so then the current text ("the last background process") already
> covers all these cases. why single out co-processes?
Yes, "background process" technically covers co-processes, but at least
for me "background processes" aka. jobs refer to those spawned with `&'
where co-processes are the definitive term for those spawned with `|&',
hence my brain wants to grep for "co-proc" and see `$!' mentioning it
to confirm that `$!' is indeed not just about jobs.

> for the reader, i think the idea of background is easier to understand
> as an umberella term, rather than asynchronous, even if it's maybe not
> so correct.
Fair enough;  I think the last diff is a slight improvement due to the
above mentioned, but I also don't have a strong opinion about it.

If the impression is that I'm complicating stuff then I'll gladly drop
the diff.

Reply | Threaded
Open this post in threaded view
|

Re: ksh.1: Mention Co-processes in $!

Jason McIntyre-2
On Sat, Aug 01, 2020 at 07:30:55PM +0200, Klemens Nanni wrote:

> On Sat, Aug 01, 2020 at 06:06:32PM +0100, Jason McIntyre wrote:
> > hmm. so then the current text ("the last background process") already
> > covers all these cases. why single out co-processes?
> Yes, "background process" technically covers co-processes, but at least
> for me "background processes" aka. jobs refer to those spawned with `&'
> where co-processes are the definitive term for those spawned with `|&',
> hence my brain wants to grep for "co-proc" and see `$!' mentioning it
> to confirm that `$!' is indeed not just about jobs.
>
> > for the reader, i think the idea of background is easier to understand
> > as an umberella term, rather than asynchronous, even if it's maybe not
> > so correct.
> Fair enough;  I think the last diff is a slight improvement due to the
> above mentioned, but I also don't have a strong opinion about it.
>
> If the impression is that I'm complicating stuff then I'll gladly drop
> the diff.
>

well, maybe someone else will chip in. but i don;t see it as an
improvement myself.

jmc