Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending SIGINT signal to script while inside close() #15303

Open
p5pRT opened this issue May 2, 2016 · 5 comments
Open

Sending SIGINT signal to script while inside close() #15303

p5pRT opened this issue May 2, 2016 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented May 2, 2016

Migrated from rt.perl.org#128056 (status was 'open')

Searchable as RT128056$

@p5pRT
Copy link
Author

p5pRT commented May 2, 2016

From @hakonhagland

I wrote the the following script ( p.pl ) as an answer to a
stackoverflow.com question ( http​://stackoverflow.com/q/36959703/2173773 ) :

use diagnostics;
use feature qw(say);
use strict;
use warnings;

$SIG{INT} = sub { say "This is expected to print"; die };
my $pid = open ( my $pipe, "|-", "script.pl" );
say "PID = $pid";
eval {
  say "Closing..";
  my $close_ok = close $pipe; # Note "close" here waits for child to exit
  if ( ! $close_ok ) {
  say "Error closing​: $!";
  }
  else {
  say "Close done.";
  }
};
if ( $@​ ) {
  say "Parent caught SIGINT.";
}

Where script.pl is given as​:

#! /usr/bin/env perl
use feature qw(say);
use strict;
use warnings;

$SIG{INT} = sub { die };
eval {
  say "Sleeping..";
  for (1..5) {
  sleep 1;
  say $_;
  }
};
if ( $@​ ) {
  say "Child caught SIGINT.";
  exit;
}

The output of running p.pl in the terminal is (if I press CTRL-C after 2
seconds)​:

PID = 1746
Closing..
Sleeping..
1
2
^CThis is expected to print
Child caught SIGINT.
Parent caught SIGINT.
Uncaught exception from user code​:
  refcnt​: fd -1 < 0

According to the discussion at the referred stackoverflow.com question, I
would like to find out​:

1) Why both child and parent receives SIGINT? And is this correct behavior?
(Note two of the other posters in the referred stackoverflow question
experienced that only the child received SIGINT (and the SIGINT was ignored
by the parent) )

2) Why do I get the message​:

Uncaught exception from user code​:
  refcnt​: fd -1 < 0

(Note​: If I don't include the "diagnostics" pragma, I only get "refcnt​: fd
-1 < 0" )

I am using Perl v5.22.1 built for x86_64-linux-gnu-thread-multi, on
Ubuntu 16.04 with gnome-terminal.

Best regards,
Håkon Hægland

@p5pRT
Copy link
Author

p5pRT commented May 2, 2016

From @Leont

On Mon, May 2, 2016 at 10​:18 PM, Håkon Hægland <perlbug-followup@​perl.org>
wrote​:

According to the discussion at the referred stackoverflow.com question, I
would like to find out​:

1) Why both child and parent receives SIGINT? And is this correct behavior?
(Note two of the other posters in the referred stackoverflow question
experienced that only the child received SIGINT (and the SIGINT was ignored
by the parent) )

The signal is send to the process group currently owning the terminal, so
yes it is correct/expected that both receive it

2) Why do I get the message​:

Uncaught exception from user code​:
refcnt​: fd -1 < 0

(Note​: If I don't include the "diagnostics" pragma, I only get "refcnt​: fd
-1 < 0" )

That does sound like a bug worth investigating.

Leon

@p5pRT
Copy link
Author

p5pRT commented May 2, 2016

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented May 2, 2016

From @cpansprout

On Mon May 02 13​:51​:30 2016, LeonT wrote​:

On Mon, May 2, 2016 at 10​:18 PM, Håkon Hægland <perlbug-
followup@​perl.org>
wrote​:

2) Why do I get the message​:

Uncaught exception from user code​:
refcnt​: fd -1 < 0

(Note​: If I don't include the "diagnostics" pragma, I only get
"refcnt​: fd
-1 < 0" )

That does sound like a bug worth investigating.

Yes. The refcnt message means that an internal consistency check failed, because the reference count on a file handle was mismanaged somehow.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented May 2, 2016

From @tonycoz

On Mon May 02 13​:18​:15 2016, hakon.hagland@​gmail.com wrote​:

I wrote the the following script ( p.pl ) as an answer to a
stackoverflow.com question ( http​://stackoverflow.com/q/36959703/2173773 ) :

use diagnostics;
use feature qw(say);
use strict;
use warnings;

$SIG{INT} = sub { say "This is expected to print"; die };
my $pid = open ( my $pipe, "|-", "script.pl" );
say "PID = $pid";
eval {
say "Closing..";
my $close_ok = close $pipe; # Note "close" here waits for child to exit
if ( ! $close_ok ) {
say "Error closing​: $!";
}
else {
say "Close done.";
}
};
if ( $@​ ) {
say "Parent caught SIGINT.";
}

Where script.pl is given as​:

#! /usr/bin/env perl
use feature qw(say);
use strict;
use warnings;

$SIG{INT} = sub { die };
eval {
say "Sleeping..";
for (1..5) {
sleep 1;
say $_;
}
};
if ( $@​ ) {
say "Child caught SIGINT.";
exit;
}

The output of running p.pl in the terminal is (if I press CTRL-C after 2
seconds)​:

PID = 1746
Closing..
Sleeping..
1
2
^CThis is expected to print
Child caught SIGINT.
Parent caught SIGINT.
Uncaught exception from user code​:
refcnt​: fd -1 < 0

According to the discussion at the referred stackoverflow.com question, I
would like to find out​:

1) Why both child and parent receives SIGINT? And is this correct behavior?
(Note two of the other posters in the referred stackoverflow question
experienced that only the child received SIGINT (and the SIGINT was ignored
by the parent) )

2) Why do I get the message​:

Uncaught exception from user code​:
refcnt​: fd -1 < 0

(Note​: If I don't include the "diagnostics" pragma, I only get "refcnt​: fd
-1 < 0" )

I am using Perl v5.22.1 built for x86_64-linux-gnu-thread-multi, on
Ubuntu 16.04 with gnome-terminal.

This looks like a duplicate of https://rt-archive.perl.org/perl5/Ticket/Display.html?id=122112

Tony

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants