LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Child exits and Parent stops?? (https://www.linuxquestions.org/questions/programming-9/child-exits-and-parent-stops-4175434143/)

x24804 10-26-2012 01:39 AM

Child exits and Parent stops??
 
Hello. I'm trying some sample code dealing with process switching, and the code I have keeps stopping the parent when the child exits.

Code snippet:

Code:

int main(int argc, char **argv) {
  int ch, rc, exit_loop = 0, round = 0, status;
  pid_t pid, pid_who = -1;

  initscr(); /* Ncurses */
  keypad(stdscr, TRUE);
  noecho();
  raw();
 
  main_win = add_win(main_win, 20, 80, 0, 0);
  update_current(main_win->thr_id);
  set_focus();

  /* Loop and poll child processes */
  while(1) {
    if(round == 0) {
      round++;

      pid = fork();

      if(pid == 0) {
        main_menu(main_win);

        _exit(EXIT_FAILURE);
      } else if(pid < 0) {
        printf("Fork failure");
        exit(EXIT_FAILURE);
      } else {
        main_win->pid = pid;

        setpgid(pid, pid);
        tcsetpgrp(STDIN_FILENO, pid);
      }
    }

    pid_who = waitpid(WAIT_ANY, &status, WNOHANG);

    if(pid_who == pid) {
      setpgid(getpid(), getpid());
      tcsetpgrp(STDIN_FILENO, getpid());

      break;
    }
  }
 
  endwin();

  exit(0);
}

Please, can anyone see why my parent's getting stopped when I exit the child process? Thank you.

millgates 10-26-2012 03:25 AM

Just a guess, but maybe it has something to do with this:

Quote:

man tcsetpgrp:
If tcsetpgrp() is called by a member of a background process group in its session, and the calling process is not blocking or ignoring SIGTTOU, a SIGTTOU signal is sent to all members of this background process group.

x24804 10-26-2012 09:02 AM

Thank You
 
millgates: Thank you very much.


All times are GMT -5. The time now is 08:40 AM.