Re: bash: please provide an easy way to spawn a new process group from script

2020-11-01 Thread clime
On Sun, 1 Nov 2020 at 21:23, Chet Ramey  wrote:
>
> On 11/1/20 5:13 AM, clime wrote:
>
> > Work with process groups should be natural in bash. It can't be that
> > complex. I struggled with this for several hours and found lots of
> > people on the net that struggled with the same problem too.
>
> It is natural, and job control is the most natural way to do it. If you
> don't want to use job control for some reason, the `setpgid' loadable
> builtin exists, as others have noted.

Job control doesn't seem to be a good solution in scripts when it has side
effects like changing the way signals are handled.

setpgid syntax looks way too complex and unusable for me anyway right now
because i need something which is supported by default.

>
> If you don't want to use the loadable builtin, you can easily write a
> standalone program that, when executed, becomes a process group leader
> and execs the remaining arguments.

That's very much something that I wouldn't want to do for a background
pipeline one-liner.

Anyway, I don't want to argue about this. If people here don't agree,
there is no point in it.
Best regards
clime

>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/



Re: bash: please provide an easy way to spawn a new process group from script

2020-11-01 Thread Chet Ramey
On 11/1/20 5:13 AM, clime wrote:

> Work with process groups should be natural in bash. It can't be that
> complex. I struggled with this for several hours and found lots of
> people on the net that struggled with the same problem too.

It is natural, and job control is the most natural way to do it. If you
don't want to use job control for some reason, the `setpgid' loadable
builtin exists, as others have noted.

If you don't want to use the loadable builtin, you can easily write a
standalone program that, when executed, becomes a process group leader
and execs the remaining arguments.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/



Re: Problem with reverse-i-search in 5.1.0(1)-rc1

2020-11-01 Thread Chet Ramey
On 10/31/20 11:00 AM, Detlef Vollmann wrote:
> Hello,
> 
> since Bash-5.1-rc1  doesn't work for me as previously.
> I have the following entries in my history:
> man a
> man b
> 
> Now I type ' m a n' and get:
> (reverse-i-search)`man': man b
> 
> Now I type '' again.
> What I would expect (and what I got with 5.0) is:
> (reverse-i-search)`man': man a
> 
> Instead I get
> (reverse-i-search)`': man b
> 
> Note the empty search string.

Thanks for the report. It's not easy to reproduce, and, as you later note,
requires the `C' or `POSIX' locales and things to be done in a certain
order, but I believe I was able to track it down. It will be fixed in
bash-5.1-rc2.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/



Re: bash: please provide an easy way to spawn a new process group from script

2020-11-01 Thread Eli Schwartz
On 11/1/20 11:48 AM, Oğuz wrote:
> 1 Kasım 2020 Pazar tarihinde clime  yazdı:
>> Hello, it doesn't work for me:
>>
>> $ export BASH_LOADABLES_BUILTIN=1
> 
> 
> by set, I meant to a path where loadable builtin binaries reside

It would be superbly helpful to mention the right variable though...

$ BASH_LOADABLES_PATH=/usr/lib/bash/
$ enable -f setpgid{,}
$ help setpgid
setpgid: setpgid pid pgrpid
invoke the setpgid(2) system call
[...]

Given the proper variable includes "_PATH", it is even self-documenting
that no, you cannot expect "1" to be remotely useful.

-- 
Eli Schwartz
Arch Linux Bug Wrangler and Trusted User



signature.asc
Description: OpenPGP digital signature


Re: bash: please provide an easy way to spawn a new process group from script

2020-11-01 Thread Oğuz
1 Kasım 2020 Pazar tarihinde clime  yazdı:

> On Sun, 1 Nov 2020 at 11:01, Oğuz  wrote:
> >
> >
> >
> > 1 Kasım 2020 Pazar tarihinde clime  yazdı:
> > ...
> >>
> >> Please, provide a syntactic construct to spawn a new process group (or
> >> at least there should be some usable command to do that).
> >>
> >
> > You can use the loadable builtin `setpgid' if you have to. Assuming
> BASH_LOADABLES_BUILTIN is set, this should work:
> >
> > enable -f setpgid{,}
> > { setpgid $BASHPID{,}; a | b; } &
> > setpgid $!{,}
> > kill -- -$!
>
> Hello, it doesn't work for me:
>
> $ export BASH_LOADABLES_BUILTIN=1


by set, I meant to a path where loadable builtin binaries reside


> $ enable -f setpgid{,}
> bash: enable: cannot open shared object setpgid: setpgid: cannot open
> shared object file: No such file or directory
>
> Also it looks quite complex. Why isn't there a simple (already
> enabled) builtin e.g. like:
>
> newpgid { a | b; } & pid=$!
>
> where pid for `{ a | b; } &` will be stored in pid and will be also
> the new gpid of the spawned process group.
>
> Work with process groups should be natural in bash. It can't be that
> complex. I struggled with this for several hours and found lots of
> people on the net that struggled with the same problem too.
>
> (in the end, i needed to do a helper function which uses ps to
> recursively collect children of that process and then i passed all
> those children to kill which is probably valid but one would expect
> bash can do this in a better way and this really delayed my work).
>
> Thank you very much
> clime
>
> >
> >
> >>
> >> Thank you
> >> clime
> >>
> >
> >
> > --
> > Oğuz
> >
>


-- 
Oğuz


Re: Problem with reverse-i-search in 5.1.0(1)-rc1

2020-11-01 Thread Detlef Vollmann

On 10/31/20 4:00 PM, Detlef Vollmann wrote:

Hello,

since Bash-5.1-rc1  doesn't work for me as previously.
I have the following entries in my history:
man a
man b

Now I type ' m a n' and get:
(reverse-i-search)`man': man b

Now I type '' again.
What I would expect (and what I got with 5.0) is:
(reverse-i-search)`man': man a

Instead I get
(reverse-i-search)`': man b

Note the empty search string.
I can type '' as often as I want, but always get the same
result.
I can type the same search string again and will stay at 'man b'.

If I now type '' to cancel the search, I get my prompt
and then still 'man b'.

If I never type '' a second time, '' works
properly (my prompt, but no command).

If I get the empty search string, I can also type a different
search string and reverse-i-search will show me a correct
match or a failure message.  If I now cancel with '',
I still get 'man b', even if a different command was shown
in the failure message.

I've tested this with the Debian package bash 5.1~rc1-2 and a
self-compiled version, no difference.

I've tested this with a test user that has no .bash*, .profile,
.inputrc, also no difference.

I've tested this on xterm, lxterminal and the Linux console
(i.e. no X11).  The only difference was that on the Linux
console the matched part of the command was highlighted.
I didn't see any highlighting in xterm.

My system is a Debian Sid, bash version string is
GNU bash, version 5.1.0(1)-rc1 (x86_64-pc-linux-gnu)

This seems the same problem as described here:
,
except thai I normally don't see highlighting.

If you need any more information, please ask.


Ok, I could narrow it down.
I'm one of those dinasaurs who still prefer the POSIX locale.
If I run 'LANG=en_US.utf8 bash'  works as expected.
(Some other things break, but that's a different story...)

So you should be able to reproduce the problem using
'LANG=POSIX bash'.

HTH,
  Detlef




Re: bash: please provide an easy way to spawn a new process group from script

2020-11-01 Thread felix
On Sun, Nov 01, 2020 at 11:13:37AM +0100, clime wrote:
> On Sun, 1 Nov 2020 at 11:01, Oğuz  wrote:
> >
> > You can use the loadable builtin `setpgid' if you have to. Assuming 
> > BASH_LOADABLES_BUILTIN is set, this should work:
> >
> > enable -f setpgid{,}
> > { setpgid $BASHPID{,}; a | b; } &
> > setpgid $!{,}
> > kill -- -$!
> 
> Hello, it doesn't work for me:
I've not found any reference about
kill -- -$!
but try this:

clear;tty=$(tty) tty=${tty#*/dev/};{
{ sleep 2; echo a ;} |
{ wc -c ; sleep 2; echo b ;}
} & ps --tty $tty fw; kill -s INT -$! ; ps --tty $tty fw

Seem make the job.

-- 
 Félix Hauri  --  http://www.f-hauri.ch



Re: bash: please provide an easy way to spawn a new process group from script

2020-11-01 Thread clime
On Sun, 1 Nov 2020 at 11:01, Oğuz  wrote:
>
>
>
> 1 Kasım 2020 Pazar tarihinde clime  yazdı:
> ...
>>
>> Please, provide a syntactic construct to spawn a new process group (or
>> at least there should be some usable command to do that).
>>
>
> You can use the loadable builtin `setpgid' if you have to. Assuming 
> BASH_LOADABLES_BUILTIN is set, this should work:
>
> enable -f setpgid{,}
> { setpgid $BASHPID{,}; a | b; } &
> setpgid $!{,}
> kill -- -$!

Hello, it doesn't work for me:

$ export BASH_LOADABLES_BUILTIN=1
$ enable -f setpgid{,}
bash: enable: cannot open shared object setpgid: setpgid: cannot open
shared object file: No such file or directory

Also it looks quite complex. Why isn't there a simple (already
enabled) builtin e.g. like:

newpgid { a | b; } & pid=$!

where pid for `{ a | b; } &` will be stored in pid and will be also
the new gpid of the spawned process group.

Work with process groups should be natural in bash. It can't be that
complex. I struggled with this for several hours and found lots of
people on the net that struggled with the same problem too.

(in the end, i needed to do a helper function which uses ps to
recursively collect children of that process and then i passed all
those children to kill which is probably valid but one would expect
bash can do this in a better way and this really delayed my work).

Thank you very much
clime

>
>
>>
>> Thank you
>> clime
>>
>
>
> --
> Oğuz
>



Re: bash: please provide an easy way to spawn a new process group from script

2020-11-01 Thread clime
Job control is subideal as I mentioned in the original email.

Thanks
clime

On Sun, 1 Nov 2020 at 09:58, Andreas Schwab  wrote:
>
> On Nov 01 2020, clime wrote:
>
> > Please, provide a syntactic construct to spawn a new process group (or
> > at least there should be some usable command to do that).
>
> Enable job control.
>
> Andreas.
>
> --
> Andreas Schwab, sch...@linux-m68k.org
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."



Re: bash: please provide an easy way to spawn a new process group from script

2020-11-01 Thread Oğuz
1 Kasım 2020 Pazar tarihinde clime  yazdı:
...

> Please, provide a syntactic construct to spawn a new process group (or
> at least there should be some usable command to do that).
>
>
You can use the loadable builtin `setpgid' if you have to. Assuming
BASH_LOADABLES_BUILTIN is set, this should work:

enable -f setpgid{,}
{ setpgid $BASHPID{,}; a | b; } &
setpgid $!{,}
kill -- -$!



> Thank you
> clime
>
>

-- 
Oğuz


Re: bash: please provide an easy way to spawn a new process group from script

2020-11-01 Thread Andreas Schwab
On Nov 01 2020, clime wrote:

> Please, provide a syntactic construct to spawn a new process group (or
> at least there should be some usable command to do that).

Enable job control.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: read with very small timeout sometime hand on stdin

2020-11-01 Thread felix
On Thu, Oct 29, 2020 at 01:57:33PM +0100, felix wrote:
> > I can't reproduce this using the following stripped-down reproducer:

Sorry to insist, but... This is not easy because not constant.

For this, I wrote a little script tested on several host, then searching
for installation that was not mine... Tested at https://www.jdoodle.com/ia/3EO

  $ sed <<"eotest" >/tmp/test-timeout-race.sh 's/^//'
#!/bin/bash

declare -p BASH_VERSI{NFO,ON}
uptime
uname -a

po() {
for f in {1..1};do
read -t .01 v
rc=$?
[ $rc -ne 142 ] || [ "$v" ] &&
echo f:$f, v:$v, RC:$rc.
done < <(
for i in {1..1};do sleep 3;echo Timed;done
)
}

exec 2>&1
TIMEFORMAT="U:%U S:%S R:%R"
for test in {1..20};do
time po
done
eotest

If first test don't show strange** output, run test again.
 (** lines begining by `f:`)

-- 
 Félix Hauri  --  http://www.f-hauri.ch



bash: please provide an easy way to spawn a new process group from script

2020-11-01 Thread clime
I was battling this problem now for several hours

i wanted to do this:

{ a | b; } & pid=$!

and then later

kill -- -$pid

to kill all the processes spawned by the pipeline.

But this proved to be immensely complicated as no new process group is
spawned from within a script (unless set -m which is not recommended
as it blocks signals)

Please, provide a syntactic construct to spawn a new process group (or
at least there should be some usable command to do that).

Thank you
clime