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
 
Search this Thread
Old 01-13-2010, 04:20 AM   #1
ghostwhowalks
LQ Newbie
 
Registered: Jan 2010
Posts: 1

Rep: Reputation: 0
pseudo terminal problem


Hi,
I am trying to get an application working using pseudo terminal but I am run into problems with that.
I did the following to get learn how to use ptys

1. Called openpty to create master and slave file descriptors.
2. Fork
3. In the parent process, close slave fd and wait for read on master file descriptor using epoll
4. In the child process, duplicate stdin, stdout and stderr to slave file descriptor(dup2(slavefd, STDIN_FILENO)). Close both master and slave descriptor. exec a program which just reads from stdin and writes it back to stdout.

The problem with this is, when I return from epoll_wait in the parent process and I write some thing to master file descriptor, it appears back in the data read from master file descriptor along with the data written by the application executed from child process. Why is it so? Can anybody explain it please?
 
Old 01-13-2010, 08:58 PM   #2
AwesomeMachine
Senior Member
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian jessie/sid; OpenSuSE; Fedora
Posts: 1,591

Rep: Reputation: 162Reputation: 162
Are you making your own distro? Usually one can just type CTRL+ALT+F2, and a new terminal will appear.
 
Old 01-13-2010, 09:39 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,973
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 01-13-2010, 10:44 PM   #4
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 808

Rep: Reputation: 178Reputation: 178
Quote:
Originally Posted by ghostwhowalks View Post
The problem with this is, when I return from epoll_wait in the parent process and I write some thing to master file descriptor, it appears back in the data read from master file descriptor along with the data written by the application executed from child process. Why is it so? Can anybody explain it please?
A pty acts pretty much like a tty. You type a character on the keyboard. Then one appears on the screen. You send a character down the master pty, and you'll get one back. If you don't want this, you'll have to turn off the echo.

If you like, you can examine a sample program of mine which uses a pty to execute telnet and ftp commands to get mail from a shell account I have somewhere. You'll notice that it turns off the echo. The program is here. I anticipate leaving it there for at least two weeks. Download and play with it if you wish.

Hope this helps.
 
  


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
how to create a pseudo terminal jayasekar Programming 3 12-11-2009 08:18 AM
font in pseudo terminal crs_zxf Linux - Newbie 7 07-26-2009 08:38 PM
Pseudo-Terminal means? Marty21 Linux - Software 1 01-28-2009 02:53 PM
Pseudo Terminal Problem gabsik Linux - Software 8 07-25-2008 05:00 AM
pseudo terminal - scp problem vdx Programming 9 08-22-2007 03:37 AM


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

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