This source file includes following definitions.
- callback
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 }