+int Rarefact::createProcesses(vector<int>& procIters, RarefactionCurveData* rcd, int increment) {
+ try {
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+ int process = 1;
+
+ vector<int> processIDS;
+
+ EstOutput results;
+
+ //loop through and create all the processes you want
+ while (process != processors) {
+ int pid = fork();
+
+ if (pid > 0) {
+ processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later
+ process++;
+ }else if (pid == 0){
+ driver(rcd, increment, procIters[process]);
+
+ //pass numSeqs to parent
+ for(int i=0;i<displays.size();i++){
+ string tempFile = toString(getpid()) + toString(i) + ".rarefact.temp";
+ displays[i]->outputTempFiles(tempFile);
+ }
+ exit(0);
+ }else {
+ m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine();
+ for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
+ exit(0);
+ }
+ }
+
+ driver(rcd, increment, procIters[0]);
+
+ //force parent to wait until all the processes are done
+ for (int i=0;i<(processors-1);i++) {
+ int temp = processIDS[i];
+ wait(&temp);
+ }
+
+ //get data created by processes
+ for (int i=0;i<(processors-1);i++) {
+ for(int j=0;j<displays.size();j++){
+ string s = toString(processIDS[i]) + toString(j) + ".rarefact.temp";
+ displays[j]->inputTempFiles(s);
+ m->mothurRemove(s);
+ }
+ }
+
+ return 0;
+#endif
+ }
+ catch(exception& e) {
+ m->errorOut(e, "Rarefact", "createProcesses");
+ exit(1);
+ }
+}