| 10 |
|
|
| 11 |
|
#include "copyright.h" |
| 12 |
|
|
| 13 |
– |
#include <sys/types.h> |
| 13 |
|
#include <sys/wait.h> |
| 15 |
– |
#include <fcntl.h> |
| 14 |
|
#include <stdlib.h> |
| 15 |
|
|
| 16 |
|
#include "rtprocess.h" |
| 26 |
|
char *compath; |
| 27 |
|
int p0[2], p1[2]; |
| 28 |
|
|
| 29 |
< |
pd->pid = 0; |
| 29 |
> |
pd->pid = -1; |
| 30 |
|
pd->running = 0; /* not going yet */ |
| 31 |
|
|
| 32 |
|
if (av == NULL) /* cloning operation? */ |
| 35 |
|
return(0); |
| 36 |
|
if (pipe(p0) < 0 || pipe(p1) < 0) |
| 37 |
|
return(-1); |
| 38 |
< |
if ((pd->pid = fork()) == 0) { /* if child... */ |
| 38 |
> |
#ifdef BSD |
| 39 |
> |
if (compath != NULL) |
| 40 |
> |
pd->pid = vfork(); /* more efficient with exec() */ |
| 41 |
> |
else |
| 42 |
> |
#endif |
| 43 |
> |
pd->pid = fork(); |
| 44 |
> |
if (pd->pid == 0) { /* if child... */ |
| 45 |
|
close(p0[1]); |
| 46 |
|
close(p1[0]); |
| 47 |
|
if (p0[0] != 0) { /* connect p0 to stdin */ |
| 92 |
|
close(pd[i].w); |
| 93 |
|
close(pd[i].r); |
| 94 |
|
pd[i].running = 0; |
| 95 |
< |
} |
| 95 |
> |
} else |
| 96 |
> |
togo -= (pd[i].pid < 0); |
| 97 |
|
if (nproc == 1) { /* await specific process? */ |
| 98 |
|
if (waitpid(pd->pid, &status, 0) != pd->pid) |
| 99 |
|
return(-1); |
| 100 |
< |
pd->pid = 0; |
| 100 |
> |
pd->pid = -1; |
| 101 |
|
return(status>>8 & 0xff); |
| 102 |
|
} |
| 103 |
|
/* else unordered wait */ |
| 104 |
|
while (togo > 0 && (pid = wait(&status)) >= 0) { |
| 105 |
|
for (i = nproc; i-- > 0; ) |
| 106 |
|
if (pd[i].pid == pid) { |
| 107 |
< |
pd[i].pid = 0; |
| 107 |
> |
pd[i].pid = -1; |
| 108 |
|
--togo; |
| 109 |
|
break; |
| 110 |
|
} |