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

On Win32, $? is wrong after `` takes a fatal signal #11116

Open
p5pRT opened this issue Feb 7, 2011 · 4 comments
Open

On Win32, $? is wrong after `` takes a fatal signal #11116

p5pRT opened this issue Feb 7, 2011 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Feb 7, 2011

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

Searchable as RT83570$

@p5pRT
Copy link
Author

p5pRT commented Feb 7, 2011

From @nwc10

On Unix, this​:

$ perl -MPOSIX=​:sys_wait_h
`perl -e 'kill TERM, \$\$'`;
warn $?;
warn WIFEXITED($?) ? "E​: " . WEXITSTATUS($?) : WIFSIGNALED($?) ? "S​: " . WTERMSIG($?) : "!";

Gives this​:

15 at - line 2.
S​: 15 at - line 3.

This is good, and conforms with the documentation for `` and $?

dg ran it for me on Win32 (changing '' to "")

Terminating on signal SIGBREAK(21)
5376 at - line 2.
POSIX​::WIFEXITED not implemented on this architecture at - line 3.

That's buggy. $? indicates an *exit code* of 21, when it should be indicating
a fatal signal of 21.

What's wrong - the documentation or the implementation?

[He verified that ${^CHILD_ERROR_NATIVE} is identical to $? on Win32]

Nicholas Clark

@p5pRT
Copy link
Author

p5pRT commented Feb 10, 2011

From @ikegami

That's buggy. $? indicates an *exit code* of 21, when it should be
indicating a fatal signal of 21.

I don't think it's possible to determine the reason the process exited. Of
interest is

"For console processes, the default console control handler calls
ExitProcess when the console receives a CTRL+C or CTRL+BREAK signal."

I doubt that it's possible to determine that the child exited as a result of
ExitProcess being called, and I really don't see how it could be determined
that ExitProcess was called in response to the console catching a signal.

Verification would be appreciated.

What's wrong - the documentation or the implementation?

perlport could include a blurb.

- Eric

@p5pRT
Copy link
Author

p5pRT commented Feb 10, 2011

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

@p5pRT
Copy link
Author

p5pRT commented Feb 10, 2011

From @jandubois

On Thu, 10 Feb 2011, Eric Brine wrote​:

That's buggy. $? indicates an *exit code* of 21, when it should be
indicating a fatal signal of 21.

I don't think it's possible to determine the reason the process exited. Of
interest is

"For console processes, the default console control handler calls
ExitProcess when the console receives a CTRL+C or CTRL+BREAK signal."

I doubt that it's possible to determine that the child exited as a result of
ExitProcess being called, and I really don't see how it could be determined
that ExitProcess was called in response to the console catching a signal.

Verification would be appreciated.

I believe this is correct. You could probably run your child-process
under a custom debugger, which could trap the console control events and
channel this information back to you. That seems very heavy-handed
(process startup time penalty) for a really small gain. And it would
also mean that you would be creating 2 processes for every child, which
is not desirable either.

The only additional information you can get from GetExitCodeProcess() is
if the process is still alive or not by checking for exit code 259
(STILL_ACTIVE). It is not 100% reliable though, as there is nothing
preventing a program to call ExitProcess(STILL_ACTIVE), creating a dead
process that claims to be still running. :(

Cheers,
-Jan

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

No branches or pull requests

2 participants