Thread: ncurses and fork

  1. #1
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300

    ncurses and fork

    I wanted to use ncurses in a program with fork(), but it seems to screw things up. The only info I found with google were posts like this one with no reply...

    Does that mean I'm up a creek? Are there any other options for using console colors? My only thought is to include functions with lots of this:

    system("echo -e \"\[\033[1;31m\]\"");

    which works, but produces warnings due to some nested conceptualization of escape sequences -- and also does this every time:

    [] or []

    later...
    this works without warnings or extraneous output:

    Code:
    system("echo -en \"\033[1;36m\"");
    but it's still no ncurses
    Last edited by MK27; 10-03-2008 at 05:02 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    It is probably sufficient to close() the terminal descriptors immediately after forking. ncurses can't screw up a terminal that has been closed.

    For instance:

    Code:
    if(fork() == 0)
    {
        close(0);
        close(1);
        close(2);
        /* Whatever else */
    }
    You probably don't want those child processes writing to your terminal anyway, ncurses or not.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Temporarily leaving "cooked" mode seems to work too:

    Code:
    def_prog_mode();
    endwin();
    pid=fork();
    I think this is the "terminal can't get screwed up if ncurses is closed" version.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Chat Program Help?
    By Paul22000 in forum Networking/Device Communication
    Replies: 9
    Last Post: 02-10-2009, 12:35 AM
  2. Replies: 16
    Last Post: 11-10-2007, 10:48 AM

Tags for this Thread