public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* RE: 1.3.12: Process exit code's shifted up 8 bits (cwait, wait, waitpid)
@ 2002-08-25 17:27 Reddie, Steven
  0 siblings, 0 replies; 2+ messages in thread
From: Reddie, Steven @ 2002-08-25 17:27 UTC (permalink / raw)
  To: Don Sharp; +Cc: gnuwin32

What was I thinking, comparing the behaviour against Microsoft's :-)
Thanks.

-----Original Message-----
From: Don Sharp [ mailto:dwsharp@iee.org ]
Sent: Friday, 23 August 2002 6:19 PM
To: Reddie, Steven
Cc: gnuwin32
Subject: Re: 1.3.12: Process exit code's shifted up 8 bits (cwait, wait,
waitpid)




"Reddie, Steven" wrote:
> 
> There appears to be a bug in cwait and I think in other functions (wait,
> waitpid) in that the exit code of the child process is shifted up 8 bits.

This is the way it happens in Unix! If you can do a man waitpid on any
recent Unix system and it will tell you to use the supplied macros to
evaluate the status returned. (Funnily enough just yesterday we had some
code that had to be changed to evaluate the status code with the
WIFEXITED and WEXITSTATUS macros). See /usr/include/sys/wait.h


HTH

Don Sharp

> Some sample code:
> 
> #include <stdio.h>
> #include <process.h>
> 
> void main()
> {
>         char* args[] = { "cl", "/c", "foo.c", NULL };
> 
>         int pid = spawnvp(_P_NOWAIT, args[0], args);
>         if (pid != -1)
>         {
>                 int     result = 0;
>                 cwait(&result, pid, WAIT_CHILD);
>                 printf("result = %d\n", result);
>         }
> }
> 
> Output from Cygwin gcc compile (gcc -ox.exe x.c):
>         result = 512
> Output from MSVC compile (cl x.c):
>         result = 2
> 
> The reason I say that I think it is also in wait or waitpid is that I saw
> something similar when I was playing around with fork but I don't recall
the
> details.
> 
> Can someone please let me know if this isn't expected behaviour.  If it is
a
> bug I need to work around it in such a way that when it gets fixed my code
> doesn't break.  I guess I could shift the value down 8 bits only if is is
> greater than 255.  Does that sound like the best approach?
> 
> Steven
> --
> Steven Reddie <Steven.Reddie@ca.com>
> Senior Software Engineer
> Computer Associates Pty Ltd (Australia)
> 
> --
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> Bug reporting:         http://cygwin.com/bugs.html
> Documentation:         http://cygwin.com/docs.html
> FAQ:                   http://cygwin.com/faq/

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: 1.3.12: Process exit code's shifted up 8 bits (cwait, wait, waitpid)
  2002-08-23  2:24 1.3.12: Process exit code's shifted up 8 bits (cwait, wait, waitp id) Reddie, Steven
@ 2002-08-23  5:59 ` Don Sharp
  0 siblings, 0 replies; 2+ messages in thread
From: Don Sharp @ 2002-08-23  5:59 UTC (permalink / raw)
  To: Reddie, Steven; +Cc: gnuwin32



"Reddie, Steven" wrote:
> 
> There appears to be a bug in cwait and I think in other functions (wait,
> waitpid) in that the exit code of the child process is shifted up 8 bits.

This is the way it happens in Unix! If you can do a man waitpid on any
recent Unix system and it will tell you to use the supplied macros to
evaluate the status returned. (Funnily enough just yesterday we had some
code that had to be changed to evaluate the status code with the
WIFEXITED and WEXITSTATUS macros). See /usr/include/sys/wait.h


HTH

Don Sharp

> Some sample code:
> 
> #include <stdio.h>
> #include <process.h>
> 
> void main()
> {
>         char* args[] = { "cl", "/c", "foo.c", NULL };
> 
>         int pid = spawnvp(_P_NOWAIT, args[0], args);
>         if (pid != -1)
>         {
>                 int     result = 0;
>                 cwait(&result, pid, WAIT_CHILD);
>                 printf("result = %d\n", result);
>         }
> }
> 
> Output from Cygwin gcc compile (gcc -ox.exe x.c):
>         result = 512
> Output from MSVC compile (cl x.c):
>         result = 2
> 
> The reason I say that I think it is also in wait or waitpid is that I saw
> something similar when I was playing around with fork but I don't recall the
> details.
> 
> Can someone please let me know if this isn't expected behaviour.  If it is a
> bug I need to work around it in such a way that when it gets fixed my code
> doesn't break.  I guess I could shift the value down 8 bits only if is is
> greater than 255.  Does that sound like the best approach?
> 
> Steven
> --
> Steven Reddie <Steven.Reddie@ca.com>
> Senior Software Engineer
> Computer Associates Pty Ltd (Australia)
> 
> --
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> Bug reporting:         http://cygwin.com/bugs.html
> Documentation:         http://cygwin.com/docs.html
> FAQ:                   http://cygwin.com/faq/

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-08-25 17:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-25 17:27 1.3.12: Process exit code's shifted up 8 bits (cwait, wait, waitpid) Reddie, Steven
  -- strict thread matches above, loose matches on Subject: below --
2002-08-23  2:24 1.3.12: Process exit code's shifted up 8 bits (cwait, wait, waitp id) Reddie, Steven
2002-08-23  5:59 ` 1.3.12: Process exit code's shifted up 8 bits (cwait, wait, waitpid) Don Sharp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).