LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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-27-2011, 05:53 AM   #1
ring0
LQ Newbie
 
Registered: Jul 2011
Distribution: Debian
Posts: 10

Rep: Reputation: Disabled
Smile reading from a terminal device file..


hi folks,
i read some bytes from a terminal device file and then i print them in stdout.The problem is that when i start reading /dev/pts4 file the console that corresponds to that file lags and typing is a bit hard.i think that something is wrong with my code but i cannot figure out what is going wrong.

check my code

Code:
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>

int main(int argc, char **argv)
{
 char buf[5];   
 int  c;
  int i=0;
 size_t fd =open("/dev/pts/4",O_RDONLY,O_NONBLOCK);
  memset(buf,0,sizeof(buf));
  
 while(1)
 {
ssize_t  c =read(fd,buf,sizeof(buf));
     if (c==-1)
     {
       printf("error");
       return -1;
     }    
     printf("chars:%s\n",buf);

 }
return 0;
}
thanks in advance!!
 
Old 10-27-2011, 07:23 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Quote:
Originally Posted by ring0 View Post
hi folks,
i read some bytes from a terminal device file and then i print them in stdout.
Where this /dev/pts/4 comes from? As far as I know these numbers are dynamically assigned and you cannot know programming-time what they will refer run-time (if anything). (In other words: what do you really want whit this?)

PS: "O_RDONLY, O_NONBLOCK" should be O_RDONLY | O_NONBLOCK

plus there might be other important options which can be set via termios.tcsetatttr (example: http://dtelnet.sourceforge.net/shkeys.c)

Last edited by NevemTeve; 10-27-2011 at 07:26 AM.
 
Old 10-28-2011, 11:08 AM   #3
ring0
LQ Newbie
 
Registered: Jul 2011
Distribution: Debian
Posts: 10

Original Poster
Rep: Reputation: Disabled
i try to understand how the terminal interface works.So i opened a console i issued tty and i found the character device file in which the console writes data.So i thought i could read this file and when i issue a command in the console i could retrieve the command by reading the file.the problem is as i mentioned above that console lags and i am trying to fix it.
 
  


Reply



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
reading both english and arabic in mandriva2007 terminal gamor Linux - Newbie 2 04-23-2007 11:31 AM
reading and sending to terminal inlogger Programming 4 02-09-2007 11:23 AM
reading characters from terminal driver kshkid Programming 2 01-17-2006 08:02 AM
Reading a txt file in terminal over a network mdlister Programming 5 03-14-2005 07:47 AM
Reading Arabic in Linux terminal gamor Linux - Newbie 1 03-10-2005 11:16 PM

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

All times are GMT -5. The time now is 01:55 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
Open Source Consulting | Domain Registration