ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/unix_process.c
Revision: 3.5
Committed: Fri Sep 17 21:43:49 2004 UTC (19 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 3.4: +5 -4 lines
Log Message:
Added -n option to mkillum for multiprocessing on shared memory machine

File Contents

# User Rev Content
1 schorsch 3.1 #ifndef lint
2 greg 3.5 static const char RCSid[] = "$Id: unix_process.c,v 3.4 2003/11/11 16:24:06 greg Exp $";
3 schorsch 3.1 #endif
4     /*
5     * Routines to communicate with separate process via dual pipes
6     * Unix version
7     *
8     * External symbols declared in standard.h
9     */
10    
11     #include "copyright.h"
12 schorsch 3.2
13     #include <sys/types.h>
14     #include <sys/wait.h>
15 schorsch 3.1
16     #include "rtprocess.h"
17    
18    
19     int
20     open_process( /* open communication to separate process */
21     SUBPROC *pd,
22     char *av[]
23     )
24     {
25     extern char *getpath(), *getenv();
26     char *compath;
27     int p0[2], p1[2];
28    
29     pd->running = 0; /* not yet */
30     /* find executable */
31     compath = getpath(av[0], getenv("PATH"), 1);
32     if (compath == 0)
33     return(0);
34     if (pipe(p0) < 0 || pipe(p1) < 0)
35     return(-1);
36 greg 3.4 if ((pd->pid = fork()) == 0) { /* if child */
37 schorsch 3.1 close(p0[1]);
38     close(p1[0]);
39     if (p0[0] != 0) { /* connect p0 to stdin */
40     dup2(p0[0], 0);
41     close(p0[0]);
42     }
43     if (p1[1] != 1) { /* connect p1 to stdout */
44     dup2(p1[1], 1);
45     close(p1[1]);
46     }
47     execv(compath, av); /* exec command */
48     perror(compath);
49     _exit(127);
50     }
51     if (pd->pid == -1)
52     return(-1);
53     close(p0[0]);
54     close(p1[1]);
55     pd->r = p1[0];
56     pd->w = p0[1];
57     pd->running = 1;
58     return(PIPE_BUF);
59     }
60    
61    
62    
63     int
64     close_process( /* close pipes and wait for process */
65     SUBPROC *pd
66     )
67     {
68     int pid, status;
69    
70 greg 3.5 if (!pd->running)
71     return(0);
72 schorsch 3.1 close(pd->r);
73     close(pd->w);
74     pd->running = 0;
75 greg 3.5 if (waitpid(pd->pid, &status, 0) == pd->pid)
76     return(status>>8 & 0xff);
77 schorsch 3.1 return(-1); /* ? unknown status */
78     }
79    
80