| 25 | |
| 26 | |
| 27 | void MultiProc::ForkAndRun(const int procs) { |
| 28 | // start child process |
| 29 | |
| 30 | children_.resize(procs); |
| 31 | |
| 32 | for (int i(0); procs > i; ++i) { |
| 33 | pid_t pid = fork(); |
| 34 | if (pid == 0) { |
| 35 | // send SIGHUP to me if parent dies |
| 36 | prctl(PR_SET_PDEATHSIG, SIGHUP); |
| 37 | ChildRun(i); |
| 38 | exit(0); |
| 39 | } |
| 40 | children_[i] = pid; |
| 41 | } |
| 42 | |
| 43 | |
| 44 | while (true) { |
| 45 | int st; |
| 46 | pid_t pid = waitpid(-1, &st, WNOHANG); |
| 47 | if (pid <= 0) { |
| 48 | sleep(5); |
| 49 | continue; |
| 50 | } |
| 51 | |
| 52 | for (int i(0); procs > i; ++i) { |
| 53 | |
| 54 | if (children_[i] == pid) { |
| 55 | |
| 56 | pid_t pid = fork(); |
| 57 | if (pid == 0) { |
| 58 | prctl(PR_SET_PDEATHSIG, SIGHUP); |
| 59 | ChildRun(i); |
| 60 | exit(0); |
| 61 | } |
| 62 | children_[i] = pid; |
| 63 | break; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | usleep(100000); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | |
| 72 | } //namespace comm |
nothing calls this directly
no outgoing calls
no test coverage detected