prevent ignore SIGINT for asynchronous commands without enabling job control

2013-04-10 Thread Ilya Basin
Hi.
I have a script that creates some background tasks.
I want the whole tree to be killed by Ctrl-C.

There's a requirement that the script process and its children must
belong to the same process group. This is why I can't enable job
control.

I don't want to use 'trap', because it adds complexity.

Example:

#!/bin/bash
sleep 90 &
wait $!

After Ctrl-C "sleep 90" stays.

Using trap:

#!/bin/bash

trap 'trap - INT; kill -TERM $noeof_pid; kill -INT $$' INT

sleep 90 &
wait $!





Re: prevent ignore SIGINT for asynchronous commands without enabling job control

2013-04-10 Thread Dan Douglas
On Wednesday, April 10, 2013 02:43:12 PM Ilya Basin wrote:
> Hi.
> I have a script that creates some background tasks.
> I want the whole tree to be killed by Ctrl-C.

"tree"? If a script isn't coordinating with its subprocesses manually, then 
the only real guaranteed way to kill a process and all its descendants 
recursively is to use something like Linux cgroups or BSD jails. A tree of 
descendants isn't normally maintained by an OS for each process. You would 
have to go through every running process and walk the PPID chain to build a 
tree, and this will always be racy. 

> There's a requirement that the script process and its children must
> belong to the same process group. This is why I can't enable job
> control.
> 
> I don't want to use 'trap', because it adds complexity.
> 

trap is the standard (only) way to handle signals in shell. They don't have to 
be complicated.

http://mywiki.wooledge.org/ProcessManagement
http://mywiki.wooledge.org/SignalTrap

-- 
Dan Douglas



Re: prevent ignore SIGINT for asynchronous commands without enabling job control

2013-04-10 Thread konsolebox
It's actually simple with trap. Just catch SIGINT with a function and call
a function to kill the tree:

https://www.linuxquestions.org/questions/blog/konsolebox-210384/bash-functions-to-list-and-kill-or-send-signals-to-process-trees-34624/

Note killtree3. And that could be merged as one single function per your
own preference.

And do killtree3 "$BASHPID".

On Wed, Apr 10, 2013 at 6:43 PM, Ilya Basin  wrote:

> Hi.
> I have a script that creates some background tasks.
> I want the whole tree to be killed by Ctrl-C.
>
> There's a requirement that the script process and its children must
> belong to the same process group. This is why I can't enable job
> control.
>
> I don't want to use 'trap', because it adds complexity.
>
> Example:
>
> #!/bin/bash
> sleep 90 &
> wait $!
>
> After Ctrl-C "sleep 90" stays.
>
> Using trap:
>
> #!/bin/bash
>
> trap 'trap - INT; kill -TERM $noeof_pid; kill -INT $$' INT
>
> sleep 90 &
> wait $


Re: Very slow pattern substitution in parameter expansion

2013-04-10 Thread Chet Ramey
On 4/10/13 12:15 AM, Dan Douglas wrote:
> On Tuesday, April 09, 2013 10:23:34 PM Chet Ramey wrote:
>> On 4/9/13 9:56 PM, Dan Douglas wrote:
>>> Erm, here it is in a less unreadable format:
>>
>> It is pretty slow.  You forgot to enable `extglob'.
>  
> D'oh!
> 
> Bad algorithm? I suppose it's lots of backtracking and maybe has to test 
> every 
> substring for every position in the string. In my version it took about .3 of 
> a sec, but combining all that into one string with x=${a[*]}, doing the same 
> on x took about 10 seconds. It's still 0.00 in ksh/zsh.

Yep.  It's not a regexp engine, it's an interpreted-on-the-fly matcher.
There aren't as many opportunities for optimization, though I imagine
there are some.  ksh and zsh translate those patterns into regexps,
compile them, and execute them across the strings.

Chet
> 


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



RE: to - Bookmark file system locations in bash on POSIX-like systems

2013-04-10 Thread dnade.ext
Sorry to hack the thread, but I was wondering too if there was actually a 
place/list to announce such contributions.

I've recently developped https://github.com/Anvil/bash-argsparse (high level 
argument parsing library for bash) and wanted to submit it to the "bash 
community" for review, comments, and increase my own small user community.

Regards,

D

--
Damien Nadé 
Astek Sud-Est pour France Télécom - FT/OF/OFA/DMGP/PORTAIL/DOP/DEV/EAQS
Sophia Antipolis - France / Tel : 04 97 46 28 74


> -Message d'origine-
> De : bug-bash-bounces+dnade.ext=orange@gnu.org [mailto:bug-bash-
> bounces+dnade.ext=orange@gnu.org] De la part de Mara Kim
> Envoyé : jeudi 4 avril 2013 00:09
> À : bug-bash@gnu.org
> Objet : to - Bookmark file system locations in bash on POSIX-like
> systems
> 
> Hi bash devs!
> 
> I thought you guys might enjoy this simple tool I wrote.  It's under GPL
> so use it, hack it, fork it, ignore it, etc.
> 
> 
> to - Bookmark file system locations in bash (and zsh!) on POSIX-like
> systems https://github.com/resultsreturned/to
> 
> 
> Also, apologies if this is not the proper channel for this sort of
> communication.
> 
> Cheers,
> Mara

_

Ce message et ses pieces jointes peuvent contenir des informations 
confidentielles ou privilegiees et ne doivent donc
pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce 
message par erreur, veuillez le signaler
a l'expediteur et le detruire ainsi que les pieces jointes. Les messages 
electroniques etant susceptibles d'alteration,
France Telecom - Orange decline toute responsabilite si ce message a ete 
altere, deforme ou falsifie. Merci.

This message and its attachments may contain confidential or privileged 
information that may be protected by law;
they should not be distributed, used or copied without authorisation.
If you have received this email in error, please notify the sender and delete 
this message and its attachments.
As emails may be altered, France Telecom - Orange is not liable for messages 
that have been modified, changed or falsified.
Thank you.



Re: to - Bookmark file system locations in bash on POSIX-like systems

2013-04-10 Thread Roman Rakus
I think the much better would be to improve getopt command or getopts 
builtin.


RR

On 04/10/2013 03:35 PM, dnade@orange.com wrote:

Sorry to hack the thread, but I was wondering too if there was actually a 
place/list to announce such contributions.

I've recently developpedhttps://github.com/Anvil/bash-argsparse  (high level argument 
parsing library for bash) and wanted to submit it to the "bash community" for 
review, comments, and increase my own small user community.

Regards,

D

--
Damien Nadé
Astek Sud-Est pour France Télécom - FT/OF/OFA/DMGP/PORTAIL/DOP/DEV/EAQS
Sophia Antipolis - France / Tel : 04 97 46 28 74





RE: to - Bookmark file system locations in bash on POSIX-like systems

2013-04-10 Thread dnade.ext
I Agree. And IMHO, it should be more getopts than getopt, since I don't see how 
you could hook callbacks to getopt. Though, in the meantime, my work is here 
and according to the people in my work entity using it, it makes their 
shell-scripting tasks quite easier.

WRT getopts, what improvements can we expect for bash 4.3 (or later) ? Is there 
any roadmap/discussions ? Should we just submit ideas ?

D

--
Damien Nadé 
Astek Sud-Est pour France Télécom - FT/OF/OFA/DMGP/PORTAIL/DOP/DEV/EAQS
Sophia Antipolis - France / Tel : 04 97 46 28 74


> -Message d'origine-
> De : bug-bash-bounces+dnade.ext=orange@gnu.org [mailto:bug-bash-
> bounces+dnade.ext=orange@gnu.org] De la part de Roman Rakus
> Envoyé : mercredi 10 avril 2013 15:42
> À : bug-bash@gnu.org
> Objet : Re: to - Bookmark file system locations in bash on POSIX-like
> systems
> 
> I think the much better would be to improve getopt command or getopts
> builtin.
> 
> RR
> 
> On 04/10/2013 03:35 PM, dnade@orange.com wrote:
> > Sorry to hack the thread, but I was wondering too if there was
> actually a place/list to announce such contributions.
> >
> > I've recently developpedhttps://github.com/Anvil/bash-argsparse  (high
> level argument parsing library for bash) and wanted to submit it to the
> "bash community" for review, comments, and increase my own small user
> community.
> >
> > Regards,
> >
> > D
> >
> > --
> > Damien Nadé
> > Astek Sud-Est pour France Télécom -
> FT/OF/OFA/DMGP/PORTAIL/DOP/DEV/EAQS
> > Sophia Antipolis - France / Tel : 04 97 46 28 74
> 


_

Ce message et ses pieces jointes peuvent contenir des informations 
confidentielles ou privilegiees et ne doivent donc
pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce 
message par erreur, veuillez le signaler
a l'expediteur et le detruire ainsi que les pieces jointes. Les messages 
electroniques etant susceptibles d'alteration,
France Telecom - Orange decline toute responsabilite si ce message a ete 
altere, deforme ou falsifie. Merci.

This message and its attachments may contain confidential or privileged 
information that may be protected by law;
they should not be distributed, used or copied without authorisation.
If you have received this email in error, please notify the sender and delete 
this message and its attachments.
As emails may be altered, France Telecom - Orange is not liable for messages 
that have been modified, changed or falsified.
Thank you.



Re: to - Bookmark file system locations in bash on POSIX-like systems

2013-04-10 Thread Chet Ramey
On 4/10/13 9:56 AM, dnade@orange.com wrote:

> WRT getopts, what improvements can we expect for bash 4.3 (or later) ?

There are no changes in getopts between bash-4.2 and bash-4.3.  It behaves
as Posix specifies.

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