root/test/runtime/sigchld.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. callback
  2. main

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2005 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * $COPYRIGHT$
  13  *
  14  * Additional copyrights may follow
  15  *
  16  * $HEADER$
  17  */
  18 
  19 #include "ompi_config.h"
  20 #include "mpi.h"
  21 #include "orte/runtime/orte_wait.h"
  22 #include "opal/runtime/opal_progress.h"
  23 #include "runtime/runtime.h"
  24 
  25 #ifdef HAVE_SYS_TYPES_H
  26 #include <sys/types.h>
  27 #endif
  28 #ifdef HAVE_UNISTD_H
  29 #include <unistd.h>
  30 #endif
  31 #include <stdio.h>
  32 #include <stdlib.h>
  33 
  34 int count = 0;
  35 
  36 static void callback(pid_t pid, int status, void *data)
  37 {
  38     printf("callback for %d, %d\n", pid, status);
  39     count--;
  40 }
  41 
  42 
  43 int main(int argc, char *argv[])
  44 {
  45     pid_t pid, ret;
  46     int status = -1;
  47 
  48     orte_init(true);
  49 
  50     pid = fork();
  51     if (pid > 0) {
  52         count++;
  53         printf("parent launched child #1 PID %d\n", pid);
  54         orte_wait_cb(pid, callback, NULL);
  55     } else {
  56         printf("child pid %d sleeping 10 seconds\n", getpid());
  57         sleep(10);
  58         printf("pid %d exiting after sleeping 10 seconds\n", getpid());
  59         exit(0);
  60     }
  61 
  62     pid = fork();
  63     if (pid > 0) {
  64         printf("parent launched child #2 PID %d\n", pid);
  65         ret = orte_waitpid(pid, &status, 0);
  66         printf("pid %d waitpid, status %d\n", ret, status);
  67     } else {
  68         printf("child pid %d sleeping 5 seconds\n", getpid());
  69         sleep(5);
  70         printf("pid %d exiting after sleeping 5 seconds\n", getpid());
  71         exit(0);
  72     }
  73 
  74     pid = fork();
  75     if (pid > 0) {
  76         count++;
  77         printf("parent launched child #3 PID %d\n", pid);
  78         orte_wait_cb(pid, callback, NULL);
  79     } else {
  80         printf("pid %d exiting after not sleeping at all\n", getpid());
  81         exit(0);
  82     }
  83 
  84     while (count > 0) {
  85         opal_progress();
  86     }
  87 
  88     orte_finalize();
  89     return 0;
  90 }

/* [<][>][^][v][top][bottom][index][help] */