LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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
 
LinkBack Search this Thread
Old 06-03-2009, 09:33 PM   #1
whepin
Member
 
Registered: Dec 2001
Location: thunder bay, on, Canada
Distribution: Windows vista & Ubuntu
Posts: 113

Rep: Reputation: 15
How to scan user's input and output some stuff to the console at the same time?


Now I'm writing a console program. It needs to process user's input(such as some keystroke as commands) and at the same receives some data via serial ports and outputs them to the console.

I design the program using ncurses and thread library. I create two or three windows(using ncurses's newwin). One is for user's input, the other is for serial data output, the last one is for some status.

In addtion, I create two processes. One is for processing user's input, the other is for receiving data from serial ports.

But the question is , It doesnot runs well as I expected. When a process output some stuff to the console, the other process seems that it cannot grap the cpu and process my keystrokes?

I'm really confused. And I've tried a lot of methods and still can't get it working?

So anyone could help me? Any advice is welcome.

Thank you very much.

Last edited by whepin; 06-03-2009 at 09:44 PM.
 
Old 06-04-2009, 03:32 AM   #2
pgpython
Member
 
Registered: Dec 2005
Location: Sheffield, UK
Distribution: Gentoo
Posts: 141

Rep: Reputation: 32
The problem you have may well be expected. It highly depends on wether the first command is considered to be a atomic instruction if that is the case then there is nothing you can do to have the other process perform its command at the same time however if that is the case i expect your problem lies with the fact its being slowed down somewhere as if outputting typically takes a few nanoseconds as well catching the input would you notice the fact that they do perform simulteanously? Without seeing the code its difficult to say whats hogging the cpu. You could try some timing commands to see how long certain things are taking. It may be the case that you need to get one of the processes or both to sleep for a time if its in a infinite loop
 
Old 06-04-2009, 09:23 PM   #3
whepin
Member
 
Registered: Dec 2001
Location: thunder bay, on, Canada
Distribution: Windows vista & Ubuntu
Posts: 113

Original Poster
Rep: Reputation: 15
Yeah, thank you very much. You are right. If I let them sleep for some seconds , then it's ok.
But, you know, every 20 or 30 ms, I'll get data from the serial ports. So it's not possible for both of the process to sleep in my opinion.

So, are there any ideas?
Thanks again.

The following is the skeleton of my code.

pid_t child_pid = fork ();
//parent process
if (child_pid != 0)
{
while (1)
wgetch (topwin); //capture user's keystroke

}
//child process
else
{
while (1)
{
////serial operation and output to the console
}
}
 
Old 06-04-2009, 11:11 PM   #4
jdiggitydogg
Member
 
Registered: Sep 2007
Posts: 42

Rep: Reputation: 15
why don't you use 1 process & then use select() on multiple file descriptors. see 'man 2 select' for more information and an example. there's also a great example at 'man 2 select_tut'. I don't know if select is exactly what you want, but its worth looking at if you aren't familiar with it.
 
Old 06-05-2009, 03:18 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,269

Rep: Reputation: 165Reputation: 165
well first off,
as is normally the case,
I'd close stdin on the writer and stdout on the reader.

I suspect there is a problem somewhere in your control logic.
or
maybe curses isn't suitable for this.
Are you using it just for the wgetch?
try select or termios
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
INIT: open(/dev/console): Input/output error pazkaw Slackware 13 03-25-2008 05:15 PM
how do you make a poll so user's can vote on stuff samuelmp Linux - General 2 02-07-2007 02:28 PM
INIT: open(/dev/console): Input/output error nykey Slackware 12 09-21-2006 03:30 PM
open(/dev/console): Input/Output error fintanmcevoy General 2 11-18-2005 06:44 AM
Sending message to a user's console GUIPenguin Linux - General 1 10-27-2005 11:38 AM


All times are GMT -5. The time now is 06:05 AM.

Main Menu
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