Changeset 2aacbffc4255e2ba9a9963172cfd084bcbce51e3
- Timestamp:
- 07/11/09 16:41:54 (3 years ago)
- Author:
- Nedko Arnaudov <nedko@…>
- Children:
- b4eb0c7aa9dbeccc940447bfb888170ebe78fe90
- Parents:
- 8c53171ad94ee9d627dcb2209acd6570af25ab4f
- git-committer:
- Nedko Arnaudov <nedko@arnaudov.name> / 2009-07-11T16:41:54Z+0300
- Message:
-
Wait child zombies
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r8c53171
|
r2aacbff
|
|
| 50 | 50 | |
| 51 | 51 | #include <sys/types.h> |
| | 52 | #include <sys/wait.h> |
| 52 | 53 | #if defined(FORK_TIME_MEASURE) |
| 53 | 54 | # include <sys/time.h> |
| … |
… |
|
| 78 | 79 | int send_pipe; /* the pipe end that is used for sending messages to UI */ |
| 79 | 80 | int recv_pipe; /* the pipe end that is used for receiving messages from UI */ |
| | 81 | |
| | 82 | pid_t pid; |
| 80 | 83 | }; |
| 81 | 84 | |
| … |
… |
|
| 156 | 159 | else if (!strcmp(msg, "exiting")) |
| 157 | 160 | { |
| | 161 | pid_t ret; |
| | 162 | int i; |
| | 163 | |
| 158 | 164 | //printf("got UI exit notification\n"); |
| | 165 | |
| | 166 | /* wait tree seconds for child to exit, we dont like zombie processes */ |
| | 167 | for (i = 0; i < 30; i++) |
| | 168 | { |
| | 169 | //fprintf(stderr, "waitpid(%d): %d\n", (int)control_ptr->pid, i); |
| | 170 | |
| | 171 | ret = waitpid(control_ptr->pid, NULL, WNOHANG); |
| | 172 | if (ret != 0) |
| | 173 | { |
| | 174 | if (ret == -1) |
| | 175 | { |
| | 176 | fprintf(stderr, "waitpid(%d) failed: %s\n", (int)control_ptr->pid, strerror(errno)); |
| | 177 | } |
| | 178 | else if (ret == control_ptr->pid) |
| | 179 | { |
| | 180 | control_ptr->pid = -1; |
| | 181 | } |
| | 182 | else |
| | 183 | { |
| | 184 | fprintf(stderr, "we have waited for child pid %d to exit but we got pid %d instead\n", (int)control_ptr->pid, (int)ret); |
| | 185 | } |
| | 186 | |
| | 187 | break; |
| | 188 | } |
| | 189 | |
| | 190 | //fprintf(stderr, "wait 100 ms ...\n"); |
| | 191 | usleep(100000); /* wait 100 ms */ |
| | 192 | } |
| | 193 | |
| | 194 | if (control_ptr->pid != -1) |
| | 195 | { |
| | 196 | fprintf(stderr, "we have waited for child pid %d to exit for 3 seconds and we are giving up\n", (int)control_ptr->pid); |
| | 197 | } |
| | 198 | |
| 159 | 199 | control_ptr->running = false; |
| 160 | 200 | control_ptr->visible = false; |
| … |
… |
|
| 327 | 367 | control_ptr->visible = false; |
| 328 | 368 | |
| | 369 | control_ptr->pid = -1; |
| | 370 | |
| 329 | 371 | argv[0] = "python"; |
| 330 | 372 | argv[1] = filename; |
| … |
… |
|
| 377 | 419 | |
| 378 | 420 | //fprintf(stderr, FORK_STR "()-ed child process: %d\n", ret); |
| | 421 | control_ptr->pid = ret; |
| 379 | 422 | |
| 380 | 423 | /* fork duplicated the handles, close pipe ends that are used by the child process */ |