gnome-libs gnome-exec How to catch child process done ?



I want to need child process controll.(setup,kill,catch finished)
but gnome-exec functions are asyncronous only.
I need function follow this.
pi_fd uses set callback by gdk_input_add().
almost nececerly wait(or waitpid) in callback function.

int gnome_execute_shell_with_pipe(const char* dir,const char*
commandline,int pi_fd[])
{
  int parent_comm_pipes[2],child_comm_pipes[2];
  pid_t child_pid,immediate_child_pid;
  if (dir) {
    chdir(dir);
  }
  if (pipe(parent_comm_pipes)) {
    return -1;
  }
  if (pipe(child_comm_pipes)) {
    return -1;
  }
  child_pid = immediate_child_pid = fork();
  switch (child_pid) {
  case -1:
    close(parent_comm_pipes[0]);
    close(parent_comm_pipes[1]);
    return -1;
  case 0:
    close(parent_comm_pipes[1]);
    dup2(parent_comm_pipes[0],0);
    close(parent_comm_pipes[0]);
    close(child_comm_pipes[0]);
    dup2(child_comm_pipes[1],1);
    close(child_comm_pipes[1]);
    if (execlp("sh","sh","-c",commandline,NULL)<0){
      perror("");
      exit(1);
    }
    exit(0);
  default :
    close(parent_comm_pipes[0]);
    close(child_comm_pipes[1]);
    pi_fd[0] = parent_comm_pipes[1];
    pi_fd[1] = child_comm_pipes[0];
    return child_pid;
  }
}


--
##########################################
#NECinformatech Systems
#Advanced thechnical Systems 1st.
#TANGE Toshio


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]