LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 07-10-2005, 10:54 PM   #1
Yerp
Member
 
Registered: Jun 2004
Distribution: Turtle Kevux 0.8.8
Posts: 129

Rep: Reputation: 15
ncurses + fork, how to control refreshes??


Okay, I am writing an ncurses program.

The Program:
Splits screen into 3 windows, one displaying available commands, another allowing for user input with echo on and nocbreak. The third will display status information.

Once the windows are created and setup, the program will call fork.
The Parent Process will handle the input with echo
The Child Process will handle the status information.

My problem is that in order to update information in the third window I would have to call wrefresh(..). Unfortunately, this will focus the input on the third window, screwing up anything going on in the top window.

Is there a way around this? How would I tell ncurses to hold the input to window 2, and not move it to window 3?

Here is the relevant code example:
Code:
  clear();
  init_pair(1, COLOR_GREEN, COLOR_BLACK);
  
  createNCursesWindows(Left, Right, Bottom, LeftBorder, RightBorder, BottomBorder);
  
  printBorder(LeftBorder);
  printMainMenu(Right, RightBorder);
  printBorder(BottomBorder);
  
  wrefresh(Bottom);
  wrefresh(Left);
  
  nocbreak();
  echo();
  keypad(Left, true);
  //nodelay(Left, true);
  
  int PID = fork();
  
  // CHILD PROCESS
  if (PID == 0){
    while (true){
      wprintw(Bottom, "!");
      wrefresh(Bottom);
      sleep(5);
    }
  }
  // PARENT PROCESS
  else if (PID > 0){
    while (true){
      character = wgetch(Left);
    }
  }
  // FORK FAILURE
  else{
    removeNCursesWindows(Left, Right, Bottom, LeftBorder, RightBorder, BottomBorder);
    endwin();
    return false;
  }
 
Old 07-11-2005, 04:19 PM   #2
Yerp
Member
 
Registered: Jun 2004
Distribution: Turtle Kevux 0.8.8
Posts: 129

Original Poster
Rep: Reputation: 15
After observing ncurses, i have come to believe that it uses the input position to do output. Correct me if I am wrong.

If this is the case, then I have a single resource that must be shared with two seperate processes. Much like a multi-processor system. Because of this, i will probably have to impliment something like a semaphore. However, as I am only using 2 processes to interact with, I can effectivly use Peterson's Solution.

However, this results in another problem.
Updating. Developing a time interval to update the output screen while input/output can still occur in another screen would seem to be necessary. As I can see that if the output gains control for an extended period, the user will notice a sort of lag in the applications response or no respons at all.

or would threads be a better idea than forking?

.. any help on this dilema?

Last edited by Yerp; 07-11-2005 at 05:22 PM.
 
Old 07-29-2005, 06:50 PM   #3
slzckboy
Member
 
Registered: May 2005
Location: uk - Reading
Distribution: slack 10.2 kde 3.4.2 kernel 2.6.15
Posts: 452

Rep: Reputation: 30
I'm in the middle of developing a program that uses ncurses.

it will have at least two windows.One to display input from a socket file discriptor and one for to display input from the keyboad .

i'm using the select call to monitor the socket file discriptor and STDIN_FILENO(keyboard).

select can determine which file discriptor has been written to;and thus after that I am hoping it will be trivial to send the relevant output to the relevant subwindow using ncurses set_term() calls and the ncurses output functions.

thus no forking.

maybe this is an avenue you can explore????

This way you will have only one process which can make intelligent decisions what to do with iput from different sources with none of the probs you mention above.

ta

slzckboy.

Last edited by slzckboy; 07-29-2005 at 06:54 PM.
 
Old 08-08-2005, 05:09 PM   #4
Yerp
Member
 
Registered: Jun 2004
Distribution: Turtle Kevux 0.8.8
Posts: 129

Original Poster
Rep: Reputation: 15
interesting

it sounds very similar to mine.


Windows:
[ User Input ] [ Menu / Options ]
[ redirected output from something like make ]

I'll look into that idea of yours, thanks.
 
Old 08-09-2005, 03:42 PM   #5
slzckboy
Member
 
Registered: May 2005
Location: uk - Reading
Distribution: slack 10.2 kde 3.4.2 kernel 2.6.15
Posts: 452

Rep: Reputation: 30
curious how you will re-direct the output ?!!

cheers
 
  


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
Control amount of time a user may be logged in. (Parental Control) darrensnospam Mandriva 13 02-18-2006 06:01 PM
my X refreshes slowly anilkumar.as Slackware 1 05-20-2005 04:02 PM
Trailing whitespaces ( space char) and Ncurses terminal refreshes bretzeltux Programming 0 03-02-2004 03:47 PM
Can't launch redhat-network-control after updating gnome-control-center fedetxf Red Hat 0 12-12-2003 08:12 AM
ncurses-5.2-28 conflicts with file from package ncurses-5.2-12 tubby Linux - Software 4 06-16-2002 01:00 AM


All times are GMT -5. The time now is 02:40 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration