/////////////////////////////////////////////////////////////////////////////// /// Assign the parameter for coupled simulation /// ///\para cosim Pointer to the coupled simulation parameters /// ///\return 0 if no error occurred /////////////////////////////////////////////////////////////////////////////// int ffd_cosimulation(CosimulationData *cosim) { para.cosim = (CosimulationData *) malloc(sizeof(CosimulationData)); para.cosim = cosim; if(ffd(1)!=0) { cosim->para->ffdError = 1; return 1; } else return 0; } // End of ffd_cosimulation()
int main(int argc, char **argv) { signal(SIGINT, handler); while (1) { std::string args; args = readline(); if (args.length() < 1) break; std::deque<std::string> tokens; tokens = split(args, '|', tokens); pids.resize(tokens.size()); std::deque<int *> ffd(tokens.size(), new int[2]); for (int i = 0; i < tokens.size() - 1; ++i) { pipe(ffd[i]); } for (int i = 0; i < tokens.size(); ++i) { int id; if ((id = fork()) > 0) { pids[i] = id; } else { if (i != 0) { //dup2(ffd[i - 1][1], ffd[i][0]); dup2(ffd[i - 1][1], STDIN_FILENO); close(ffd[i - 1][0]); } if (i != tokens.size() - 1) { dup2(ffd[i][1], STDOUT_FILENO); } proceedCommand(tokens[i]); close(ffd[i][1]); close(ffd[i][0]); } if (id < 0) return 0; } for (int i = 0, j; i < tokens.size(); ++i) { waitpid(pids[i], &j, 0); } for (int i = 0; i < tokens.size() - 1; ++i) { close(ffd[i][0]); close(ffd[i][1]); } pids.clear(); } }