ExitProcess does not work in Cygwin?
Jay K
jayk123@hotmail.com
Thu Jan 13 23:15:11 GMT 2022
> Just use POSIX exit(3)!
I did switch my code:
#ifdef __CYGWIN__
exit(x);
#else
ExitProcess(x);
#endif
.
I think the problem is actually in how "Cygwin bash"
aka Cygwin, computes the exit code in exec/spawn/system.
I.e. it recognizes it is running a Cygwin exe or a native
exe and does things differently.
I admit I didn't read or debug much.
In one run I was debugging I did seem to see a crash
in some DllMain(process detach), without symbols, and then I seemed to see
ExitProcess(1 or 2) become ExitProcess(0xXX00) and
then I started wondering if Cygwin somewhere is only
taking the lower 8 bits, since I know that is a thing in some code.
But I didn't dig into this further before trying the simple case,
which I don't think crashes and really does NtTerminateProcess(1).
- Jay
________________________________
From: Brian Inglis <Brian.Inglis@SystematicSw.ab.ca>
Sent: Thursday, January 13, 2022 5:19 PM
To: cygwin@cygwin.com <cygwin@cygwin.com>
Cc: Jay K <jayk123@hotmail.com>
Subject: Re: ExitProcess does not work in Cygwin?
On 2022-01-13 10:07, Kaz Kylheku (Cygwin) wrote:
> On 2022-01-13 05:40, Eliot Moss wrote:
>> On 1/13/2022 1:39 AM, Jay K wrote:
>>> ExitProcess does not work in Cygwin?
Just use POSIX exit(3)!
>> ExitProcess does not appear to be a POSIX function.
>
> This is a real issue worth looking into. Though ExitProcess isn't a POSIX
> function, Cygwin can capture the termination status of non-Cygwin programs.
>
> The concept of termination status cannot be entirely walled off in a
> private Cygwin garden; it belongs to the underlying platform.
>
> In Cygwin, I can do this:
>
> C:\Cygwin\cygwin64\home\kaz>exit 1
> 1:BLACKBOX:~$
> 1:BLACKBOX:~$ echo $?
> 1
> 0:BLACKBOX:~$ cmd
> Microsoft Windows [Version 10.0.19042.1052]
> (c) Microsoft Corporation. All rights reserved.
>
> C:\Cygwin\cygwin64\home\kaz>exit 0
> 0:BLACKBOX:~$
>
> The number in my Bash prompt is the last exit code. As you can see,
> the non-Cygwin CMD.EXE program produces a termination code which
> is recognized in the Cygwin world.
>
> Most likely it does that via ExitProcess.
>
> It is odd if calling ExitProcess in a Cygwin process causes
> a Cygwin parent not to similarly process the status, as seems
> to be shown by Jay's test cases.
>
> Cygwin supports non-POSIX programming; you can write GUI applications
> using Win32 calls for instance.
>
> (Now I agree that for exiting your process, even if it's a GUI
> application using numerous win32 calls, you should probably do it the
> Cygwin way, and use exit, or return from main. But still ...)
Cygwin installs at-exit handlers and it is likely that when these have
finished, they return a Cygwin exit status if passed by the POSIX
function, perhaps unless some error has occurred during at-exit handling.
--
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada
This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.
[Data in binary units and prefixes, physical quantities in SI.]
More information about the Cygwin
mailing list