Changeset 2aacbffc4255e2ba9a9963172cfd084bcbce51e3

Show
Ignore:
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:
1 modified

Legend:

Unmodified
Added
Removed
  • lv2_ui.c

    r8c53171 r2aacbff  
    5050 
    5151#include <sys/types.h> 
     52#include <sys/wait.h> 
    5253#if defined(FORK_TIME_MEASURE) 
    5354# include <sys/time.h> 
     
    7879  int send_pipe;             /* the pipe end that is used for sending messages to UI */ 
    7980  int recv_pipe;             /* the pipe end that is used for receiving messages from UI */ 
     81 
     82  pid_t pid; 
    8083}; 
    8184 
     
    156159  else if (!strcmp(msg, "exiting")) 
    157160  { 
     161    pid_t ret; 
     162    int i; 
     163 
    158164    //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 
    159199    control_ptr->running = false; 
    160200    control_ptr->visible = false; 
     
    327367  control_ptr->visible = false; 
    328368 
     369  control_ptr->pid = -1; 
     370 
    329371  argv[0] = "python"; 
    330372  argv[1] = filename; 
     
    377419 
    378420  //fprintf(stderr, FORK_STR "()-ed child process: %d\n", ret); 
     421  control_ptr->pid = ret; 
    379422 
    380423  /* fork duplicated the handles, close pipe ends that are used by the child process */