Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

You have mail.


devel / comp.unix.shell / Re: trap doesn't respond control-c correctly.

SubjectAuthor
* trap doesn't respond control-c correctly.hongy...@gmail.com
+- Re: trap doesn't respond control-c correctly.Kees Nuyt
+* Re: trap doesn't respond control-c correctly.Ben Bacarisse
|`* Re: trap doesn't respond control-c correctly.hongy...@gmail.com
| `* Re: trap doesn't respond control-c correctly.Ben Bacarisse
|  `- Re: trap doesn't respond control-c correctly.hongy...@gmail.com
`- Re: trap doesn't respond control-c correctly.Ed Morton

1
trap doesn't respond control-c correctly.

<32392b35-6489-46c0-8027-bc50dfd0a8a0n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5890&group=comp.unix.shell#5890

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ae9:f707:0:b0:6fa:8b0b:10c9 with SMTP id s7-20020ae9f707000000b006fa8b0b10c9mr57303043qkg.732.1670143622896;
Sun, 04 Dec 2022 00:47:02 -0800 (PST)
X-Received: by 2002:a05:6830:6019:b0:661:cac2:79ca with SMTP id
bx25-20020a056830601900b00661cac279camr33794286otb.93.1670143622619; Sun, 04
Dec 2022 00:47:02 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sun, 4 Dec 2022 00:47:02 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=103.149.249.17; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 103.149.249.17
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <32392b35-6489-46c0-8027-bc50dfd0a8a0n@googlegroups.com>
Subject: trap doesn't respond control-c correctly.
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Sun, 04 Dec 2022 08:47:02 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1732
 by: hongy...@gmail.com - Sun, 4 Dec 2022 08:47 UTC

Hi here,
On Ubuntu 22.10, I'm using the following shipped bash version:

$ bash --version
GNU bash, version 5.2.2(1)-release (x86_64-pc-linux-gnu)

In my case, I've a bash script which has the following line in it:

trap 'echo -en "\n*** Ouch! Exiting ***\n"; sudo kill -- -$(ps -o pgid= $$ | egrep -o [0-9]+); exit 1' 2

Then when the script is running, when I hit the control-c, I just noticed the following information given on the screen:

blabla (Here is the normal information given by the script when running).
^C

This issue did not occur until I upgraded to this version of the operating system. I'm very confused by this behavior.

Any comments and tips will be appreciated.

Regards,
Zhao

Re: trap doesn't respond control-c correctly.

<ntepohl4m9q4vd90cjhrpq97q0el61kvr8@dim53.demon.nl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5891&group=comp.unix.shell#5891

  copy link   Newsgroups: comp.unix.shell
From: k.n...@nospam.demon.nl (Kees Nuyt)
Newsgroups: comp.unix.shell
Subject: Re: trap doesn't respond control-c correctly.
Date: Sun, 04 Dec 2022 16:34:58 +0100
Reply-To: k.nuyt@nospam.demon.nl
Message-ID: <ntepohl4m9q4vd90cjhrpq97q0el61kvr8@dim53.demon.nl>
References: <32392b35-6489-46c0-8027-bc50dfd0a8a0n@googlegroups.com>
User-Agent: ForteAgent/7.10.32.1214
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!94.232.112.244.MISMATCH!feed.abavia.com!abe004.abavia.com!abp003.abavia.com!news.kpn.nl!not-for-mail
Lines: 38
Injection-Date: Sun, 04 Dec 2022 16:34:59 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
 by: Kees Nuyt - Sun, 4 Dec 2022 15:34 UTC

On Sun, 4 Dec 2022 00:47:02 -0800 (PST), "hongy...@gmail.com"
<hongyi.zhao@gmail.com> wrote:

> On Ubuntu 22.10, I'm using the following shipped bash version:
>
> $ bash --version
> GNU bash, version 5.2.2(1)-release (x86_64-pc-linux-gnu)
>
> In my case, I've a bash script which has the following line in it:
>
> trap 'echo -en "\n*** Ouch! Exiting ***\n"; sudo kill -- -$(ps -o pgid= $$ | egrep -o [0-9]+); exit 1' 2
>
> Then when the script is running, when I hit the control-c,
> I just noticed the following information given on the screen:
>
> blabla (Here is the normal information given by the script when running).
> ^C
>
> This issue did not occur until I upgraded to this version of the
> operating system. I'm very confused by this behavior.

With GNU bash, version 5.0.3(1)-release
(arm-unknown-linux-gnueabihf) I get:

blah
blah
^C
*** Ouch! Exiting ***
Terminated
$

So you will have to read the release notes of bash between your
previous version and the current one.

--
Regards,
Kees Nuyt

Re: trap doesn't respond control-c correctly.

<87359v5epz.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5892&group=comp.unix.shell#5892

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: trap doesn't respond control-c correctly.
Date: Sun, 04 Dec 2022 16:13:44 +0000
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <87359v5epz.fsf@bsb.me.uk>
References: <32392b35-6489-46c0-8027-bc50dfd0a8a0n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="209caabdbb37f04b2875517e086d5abb";
logging-data="3901511"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19OOZtaT2zZJ5hTlmlBjQ8/Org8YK3VJeU="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:chWmUiM478ScNwtkZEcsyU6lYW0=
sha1:Q9ZT/sm5tFkeQjcDtCGE87EHbF8=
X-BSB-Auth: 1.212a69bbfb08b9a1f8c2.20221204161344GMT.87359v5epz.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 4 Dec 2022 16:13 UTC

"hongy...@gmail.com" <hongyi.zhao@gmail.com> writes:

> On Ubuntu 22.10, I'm using the following shipped bash version:
>
> $ bash --version
> GNU bash, version 5.2.2(1)-release (x86_64-pc-linux-gnu)

Same here.

> In my case, I've a bash script which has the following line in it:
>
> trap 'echo -en "\n*** Ouch! Exiting ***\n"; sudo kill -- -$(ps -o
> pgid= $$ | egrep -o [0-9]+); exit 1' 2

What's all the ps and egrep stuff for? Isn't the net effect just $$?

> Then when the script is running, when I hit the control-c, I just
> noticed the following information given on the screen:
>
> blabla (Here is the normal information given by the script when
> running). ^C
>
> This issue did not occur until I upgraded to this version of the
> operating system. I'm very confused by this behavior.

Presumably the issue is that the trap does not work, but it does for
me. Is Ctrl-C sending the right signal?

Can you post a minimal example that fails for you? This example:

#!/bin/bash

trap 'echo -en "\n*** Ouch! Exiting ***\n"; exit 1' 2

while true; do
echo blah
done

works for me:

$ ./script
blah
blah
blah
blah
blah
blah
^C./script: line 6: echo: write error: Interrupted system call

*** Ouch! Exiting ***

--
Ben.

Re: trap doesn't respond control-c correctly.

<tmique$3nupd$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5893&group=comp.unix.shell#5893

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: mortons...@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: trap doesn't respond control-c correctly.
Date: Sun, 4 Dec 2022 13:03:42 -0600
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <tmique$3nupd$1@dont-email.me>
References: <32392b35-6489-46c0-8027-bc50dfd0a8a0n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 4 Dec 2022 19:03:42 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="706471b2d157a625fb045e59a9e74ee8";
logging-data="3930925"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+B0q1sfQ+8eDpLezUb12Wn"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.5.1
Cancel-Lock: sha1:C9pN3waqHXlHIItL1rtEMYWZI5Y=
X-Antivirus-Status: Clean
X-Antivirus: Avast (VPS 221204-6, 12/4/2022), Outbound message
In-Reply-To: <32392b35-6489-46c0-8027-bc50dfd0a8a0n@googlegroups.com>
Content-Language: en-US
 by: Ed Morton - Sun, 4 Dec 2022 19:03 UTC

On 12/4/2022 2:47 AM, hongy...@gmail.com wrote:
> Hi here,
>
> On Ubuntu 22.10, I'm using the following shipped bash version:
>
> $ bash --version
> GNU bash, version 5.2.2(1)-release (x86_64-pc-linux-gnu)
>
> In my case, I've a bash script which has the following line in it:
>
> trap 'echo -en "\n*** Ouch! Exiting ***\n"; sudo kill -- -$(ps -o pgid= $$ | egrep -o [0-9]+); exit 1' 2
>
>
> Then when the script is running, when I hit the control-c, I just noticed the following information given on the screen:
>
> blabla (Here is the normal information given by the script when running).
> ^C
>
> This issue did not occur until I upgraded to this version of the operating system. I'm very confused by this behavior.
>
> Any comments and tips will be appreciated.
>
> Regards,
> Zhao

The most common source of confusion in this area is, I think, when
people are running a shell that calls another command in a sub-shell.
They send an interrupt and the sub-shell gets the interrupt but the
subshell traps the interrupt to handle it itself and then doesn't exit
with an interrupt exit status so the calling shell where you expect to
see an interrupt trapped doesn't fire because that shell doesn't know an
interrupt happened.

We can't help you diagnose a problem in a script given just 1 line of
the script though - create and provide a **MINIMAL** complete sample
script that has this problem and then we can help you.

Also, if you google for things like "bash interrupt subshell" you'll get
some hits with more info on this topic. Also see
https://mywiki.wooledge.org/SignalTrap.

Ed.

Re: trap doesn't respond control-c correctly.

<3eb7e2df-1dfa-40f7-849e-4be6eae7f879n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5896&group=comp.unix.shell#5896

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:620a:3714:b0:6fa:16fe:93f6 with SMTP id de20-20020a05620a371400b006fa16fe93f6mr69508164qkb.258.1670202626121;
Sun, 04 Dec 2022 17:10:26 -0800 (PST)
X-Received: by 2002:a05:6870:1710:b0:144:9c7f:927e with SMTP id
h16-20020a056870171000b001449c7f927emr1354836oae.40.1670202625798; Sun, 04
Dec 2022 17:10:25 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sun, 4 Dec 2022 17:10:25 -0800 (PST)
In-Reply-To: <87359v5epz.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=103.149.249.17; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 103.149.249.17
References: <32392b35-6489-46c0-8027-bc50dfd0a8a0n@googlegroups.com> <87359v5epz.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3eb7e2df-1dfa-40f7-849e-4be6eae7f879n@googlegroups.com>
Subject: Re: trap doesn't respond control-c correctly.
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Mon, 05 Dec 2022 01:10:26 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2914
 by: hongy...@gmail.com - Mon, 5 Dec 2022 01:10 UTC

On Monday, December 5, 2022 at 12:13:50 AM UTC+8, Ben Bacarisse wrote:
> "hongy...@gmail.com" <hongy...@gmail.com> writes:
>
> > On Ubuntu 22.10, I'm using the following shipped bash version:
> >
> > $ bash --version
> > GNU bash, version 5.2.2(1)-release (x86_64-pc-linux-gnu)
> Same here.
> > In my case, I've a bash script which has the following line in it:
> >
> > trap 'echo -en "\n*** Ouch! Exiting ***\n"; sudo kill -- -$(ps -o
> > pgid= $$ | egrep -o [0-9]+); exit 1' 2
> What's all the ps and egrep stuff for? Isn't the net effect just $$?

I've a bunch of other processes spawned from this script, and I hope to kill them all, so that the orphan process will not be left behind.

> > Then when the script is running, when I hit the control-c, I just
> > noticed the following information given on the screen:
> >
> > blabla (Here is the normal information given by the script when
> > running). ^C
> >
> > This issue did not occur until I upgraded to this version of the
> > operating system. I'm very confused by this behavior.
> Presumably the issue is that the trap does not work, but it does for
> me. Is Ctrl-C sending the right signal?
>
> Can you post a minimal example that fails for you? This example:
>
> #!/bin/bash
>
> trap 'echo -en "\n*** Ouch! Exiting ***\n"; exit 1' 2
>
> while true; do
> echo blah
> done
>
> works for me:
>
> $ ./script
> blah
> blah
> blah
> blah
> blah
> blah
> ^C./script: line 6: echo: write error: Interrupted system call
>
> *** Ouch! Exiting ***

I observed the same behavior as you. But my real original script is rather complicated, and it will take some time to work out a minimal example.
> --
> Ben.

Zhao

Re: trap doesn't respond control-c correctly.

<87o7si3b20.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5897&group=comp.unix.shell#5897

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: trap doesn't respond control-c correctly.
Date: Mon, 05 Dec 2022 01:15:51 +0000
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <87o7si3b20.fsf@bsb.me.uk>
References: <32392b35-6489-46c0-8027-bc50dfd0a8a0n@googlegroups.com>
<87359v5epz.fsf@bsb.me.uk>
<3eb7e2df-1dfa-40f7-849e-4be6eae7f879n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="badf407f0a0a4ea653bd6f12e51aaa12";
logging-data="3983780"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ZCqYoQI6Y72wI7lCcMaCT/Z33GYqJMG0="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:R0GZsKCpOew68lq24IxQ3Gr9x4c=
sha1:LyegIa/KEd3uDp507TM/EkEai3w=
X-BSB-Auth: 1.4fe0db2cac7cbd5d7df0.20221205011551GMT.87o7si3b20.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 5 Dec 2022 01:15 UTC

"hongy...@gmail.com" <hongyi.zhao@gmail.com> writes:

> On Monday, December 5, 2022 at 12:13:50 AM UTC+8, Ben Bacarisse wrote:
>> "hongy...@gmail.com" <hongy...@gmail.com> writes:
>>
>> > On Ubuntu 22.10, I'm using the following shipped bash version:
>> >
>> > $ bash --version
>> > GNU bash, version 5.2.2(1)-release (x86_64-pc-linux-gnu)
>> Same here.
>> > In my case, I've a bash script which has the following line in it:
>> >
>> > trap 'echo -en "\n*** Ouch! Exiting ***\n"; sudo kill -- -$(ps -o
>> > pgid= $$ | egrep -o [0-9]+); exit 1' 2
>> What's all the ps and egrep stuff for? Isn't the net effect just $$?
>
> I've a bunch of other processes spawned from this script, and I hope
> to kill them all, so that the orphan process will not be left behind.

Ed Morton called it! Did you read his reply?

--
Ben.

Re: trap doesn't respond control-c correctly.

<58d23d33-9a59-4622-b0f9-18940bc78afcn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5898&group=comp.unix.shell#5898

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:6214:1088:b0:4c7:4792:46b5 with SMTP id o8-20020a056214108800b004c7479246b5mr10543711qvr.112.1670206845412;
Sun, 04 Dec 2022 18:20:45 -0800 (PST)
X-Received: by 2002:a05:6808:16a9:b0:35a:76f3:f550 with SMTP id
bb41-20020a05680816a900b0035a76f3f550mr39116803oib.219.1670206845151; Sun, 04
Dec 2022 18:20:45 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sun, 4 Dec 2022 18:20:44 -0800 (PST)
In-Reply-To: <87o7si3b20.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=103.149.249.17; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 103.149.249.17
References: <32392b35-6489-46c0-8027-bc50dfd0a8a0n@googlegroups.com>
<87359v5epz.fsf@bsb.me.uk> <3eb7e2df-1dfa-40f7-849e-4be6eae7f879n@googlegroups.com>
<87o7si3b20.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <58d23d33-9a59-4622-b0f9-18940bc78afcn@googlegroups.com>
Subject: Re: trap doesn't respond control-c correctly.
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Mon, 05 Dec 2022 02:20:45 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2395
 by: hongy...@gmail.com - Mon, 5 Dec 2022 02:20 UTC

On Monday, December 5, 2022 at 9:15:57 AM UTC+8, Ben Bacarisse wrote:
> "hongy...@gmail.com" <hongy...@gmail.com> writes:
>
> > On Monday, December 5, 2022 at 12:13:50 AM UTC+8, Ben Bacarisse wrote:
> >> "hongy...@gmail.com" <hongy...@gmail.com> writes:
> >>
> >> > On Ubuntu 22.10, I'm using the following shipped bash version:
> >> >
> >> > $ bash --version
> >> > GNU bash, version 5.2.2(1)-release (x86_64-pc-linux-gnu)
> >> Same here.
> >> > In my case, I've a bash script which has the following line in it:
> >> >
> >> > trap 'echo -en "\n*** Ouch! Exiting ***\n"; sudo kill -- -$(ps -o
> >> > pgid= $$ | egrep -o [0-9]+); exit 1' 2
> >> What's all the ps and egrep stuff for? Isn't the net effect just $$?
> >
> > I've a bunch of other processes spawned from this script, and I hope
> > to kill them all, so that the orphan process will not be left behind.
> Ed Morton called it! Did you read his reply?

I've read Ed Morton's valuable reply and am trying to find the root of the problem based on his comments. Still, it seems like a needle-in-a-haystack problem, at least for now.
> --
> Ben.

Zhao

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor