LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-26-2012, 01:39 AM   #1
x24804
LQ Newbie
 
Registered: Jun 2007
Posts: 12

Rep: Reputation: 0
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.
 
Old 10-26-2012, 03:25 AM   #2
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
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.
 
Old 10-26-2012, 09:02 AM   #3
x24804
LQ Newbie
 
Registered: Jun 2007
Posts: 12

Original Poster
Rep: Reputation: 0
Thank You

millgates: Thank you very much.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Parent and child process Iyyaaz Programming 4 01-02-2011 11:20 AM
File descriptors shared between child and parent causing parent to hang. bharadiaam Linux - Newbie 1 03-02-2009 01:01 AM
how to retain changes made in a global variable by a child process after in exits sagsriv Linux - Newbie 3 03-12-2008 12:44 AM
parent and child processes skora Programming 5 11-02-2003 10:41 AM
about parent and child process winwar Solaris / OpenSolaris 3 07-23-2003 06:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration