This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: WCONTINUED/WIFCONTINUED


Reini Urban wrote:
> Any volunteer for WCONTINUED, WIFCONTINUED() for wait4() for the
> initial cygwin-1.7 release?
> See http://www.opengroup.org/onlinepubs/009695399/functions/wait.html
> 
> Sorry, I'm not able to write this, but I have looked into wait.cc.

  ?  They appear to exist and work.  See "/usr/include/cygwin/wait.h".
Attached: crude smoketest derived from the opengroup web page linked above.

    cheers,
      DaveK


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>

int main (int argc, const char **argv)
{

    pid_t child_pid, wpid;
    int status;


    child_pid = fork();
    if (child_pid == -1) {      /* fork() failed */
        perror("fork");
        exit(EXIT_FAILURE);
    }

    if (child_pid == 0) {       /* This is the child */
        /* Child does some work and then terminates */
        printf ("In child!\n");
        fflush (0);
/* TRY WITH OR WITHOUT THIS LINE. */
	  * (int * ) 0 = 0;
/* TRY CHANGING THIS VALUE. */
        return 42;
    } else {                    /* This is the parent */
        do {
            wpid = waitpid(child_pid, &status, WUNTRACED
    #ifdef WCONTINUED       /* Not all implementations support this */
            | WCONTINUED
    #endif
            );
            if (wpid == -1) {
                perror("waitpid");
                exit(EXIT_FAILURE);
            }

            if (WIFEXITED(status)) {
                printf("child exited, status=%d\n", WEXITSTATUS(status));
            } else if (WIFSIGNALED(status)) {
                printf("child killed (signal %d)\n", WTERMSIG(status));
            } else if (WIFSTOPPED(status)) {
                printf("child stopped (signal %d)\n", WSTOPSIG(status));
    #ifdef WIFCONTINUED     /* Not all implementations support this */
            } else if (WIFCONTINUED(status)) {
                printf("child continued\n");
    #endif
            } else {    /* Non-standard case -- may never happen */
                printf("Unexpected status (0x%x)\n", status);
            }
        } while (!WIFEXITED(status) && !WIFSIGNALED(status));
    }
  return 0;
}


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]