| | 319 | |
| | 320 | #ifndef WIN32 // no waitpid() on Windows |
| | 321 | void WaitForChildren() |
| | 322 | { |
| | 323 | int p = 0; |
| | 324 | do |
| | 325 | { |
| | 326 | int status = 0; |
| | 327 | p = ::waitpid(0 /* any child in process group */, |
| | 328 | &status, WNOHANG); |
| | 329 | |
| | 330 | if(p == -1 && errno != ECHILD && errno != EINTR) |
| | 331 | { |
| | 332 | THROW_EXCEPTION(ServerException, |
| | 333 | ServerWaitOnChildError) |
| | 334 | } |
| | 335 | else if(p == 0) |
| | 336 | { |
| | 337 | // no children exited, will return from |
| | 338 | // function |
| | 339 | } |
| | 340 | else if(WIFEXITED(status)) |
| | 341 | { |
| | 342 | BOX_INFO("child process " << p << " " |
| | 343 | "terminated normally"); |
| | 344 | } |
| | 345 | else if(WIFSIGNALED(status)) |
| | 346 | { |
| | 347 | int sig = WTERMSIG(status); |
| | 348 | BOX_ERROR("child process " << p << " " |
| | 349 | "terminated abnormally with " |
| | 350 | "signal " << sig); |
| | 351 | } |
| | 352 | else |
| | 353 | { |
| | 354 | BOX_WARNING("something unknown happened " |
| | 355 | "to child process " << p << ": " |
| | 356 | "status = " << status); |
| | 357 | } |
| | 358 | } |
| | 359 | while(p > 0); |
| | 360 | } |
| | 361 | #endif |