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

SIGCHLD and qx() #9877

Open
p5pRT opened this issue Sep 18, 2009 · 4 comments
Open

SIGCHLD and qx() #9877

p5pRT opened this issue Sep 18, 2009 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Sep 18, 2009

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

Searchable as RT69212$

@p5pRT
Copy link
Author

p5pRT commented Sep 18, 2009

From @MaikHentscheAMD

Please find the bug report generated by perlbug attached.

so long
Maik

--
Operating \ Advanced Micro Devices GmbH
  System | Karl-Hammerschmidt-Str. 34, 85609 Dornach
Research | Registergericht München, HRB Nr. 43632
  Center / Sitz​: Dornach, Gemeinde Aschheim, Landkreis München
  Geschäftsführer​: Thomas McCoy;Giuliano Meroni

@p5pRT
Copy link
Author

p5pRT commented Sep 18, 2009

From @MaikHentscheAMD

bugreport

@p5pRT
Copy link
Author

p5pRT commented Sep 18, 2009

From @ikegami

On Fri, Sep 18, 2009 at 6​:16 AM, Maik Hentsche <perlbug-followup@​perl.org>wrote​:

# New Ticket Created by Maik Hentsche
# Please include the string​: [perl #69212]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org/rt3/Ticket/Display.html?id=69212 >

When you use qx() together with fork() and wait() you get unexpected

results.
[...]
I consider this a bug.

In Perl or in your code? That's debatable. You can stop stepping on qx's
feet using the following​:

use strict;
use warnings;

use POSIX qw( WNOHANG );

my %pids_to_handle;

$SIG{CHLD} = sub {
  for my $pid (keys %pids_to_handle) {
  my $rv = waitpid($pid, WNOHANG);
  if ($rv < 0) {
  warn("[warning] waitpid​: $!\n");
  delete $pids_to_handle{$pid};
  }
  if ($rv > 0) {
  print("Child exited with \$? = $?\n");
  delete $pids_to_handle{$pid};
  }
  }
};

my $pid=fork();
if ($pid==0){
  sleep 10;
  exit 0;
} else {
  ++$pids_to_handle{$pid};
  print "my child id $pid\n";
  qx(/bin/true);
  sleep while %pids_to_handle;
}

@p5pRT
Copy link
Author

p5pRT commented Sep 18, 2009

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

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