24 #include <sys/types.h>
50 int to_child[2],from_child[2],ret;
56 ret = ::pipe(to_child);
57 if(ret == -1)
return -1;
58 ret = ::pipe(from_child);
59 if(ret == -1)
return -1;
61 if((
pid = ::fork()) == 0)
65 ::dup2(to_child[0],0);
68 if(from_child[1] != 2)
70 ::dup2(from_child[1] ,2);
72 if(from_child[1] != 1)
74 ::dup2(from_child[1],1);
75 ::close(from_child[1]);
78 ::close(from_child[0]);
84 ::close(from_child[1]);
85 toChild = (
void*) ::fdopen(to_child[1],
"w");
86 if(
toChild == NULL) {
return -1; }
87 fromChild = (
void*) ::fdopen(from_child[0],
"r");
102 waitpid(
pid, &status, 0);
123 return ::write(fileno((FILE*)
toChild),buf,len);
136 if(ret < 0)
return ret;
137 return write(message,strlen(message));
143 return fprintf((FILE*)
toChild,
"%s",buf);
157 struct timeval timout;
158 fd_set wset,rset,eset;
169 timout.tv_sec = timeout / 1000;
170 timout.tv_usec = (timeout % 1000) * 1000;
172 ret =
::select(maxfdp1,&rset,&wset,&eset,&timout);
173 if(ret == 0)
return 0;