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



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 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
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/