Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-05-2014, 12:47 PM   #1
LQ Newbie
Registered: Dec 2014
Posts: 13

Rep: Reputation: Disabled
tcgetattr,tcsetpgrp, tcsetattr and other terminal functions

I really need your help. I have studied and read a lot of information about this. But still don't understand anything. I cannot get it for a long time. SO I hope someone can help to understand this stuff.I think that I also don't understand what is really tty, in my view it is virtual devices that is used as abstraction layer between user input/output and kernel of linux , these devices are sending info to system using ioctl interface. And it sending back output. This is required only when communicating with kernel directly sending requests. GUI in turn in some way break out from terminal (I don't know how, please explain) and doesn't interact with you using pseudo devices.
Am I correct ?
I am interesting in how can I run backround tasks from terminal, as using ampersand (&) in shells. I have read that this functions helps to do this. But I don't understand how.
What is the purpose of this functions.
Firstly ,

tcsetattr - set the parameters associated with the terminal
What is a terminal in this case ? It is /dev/tty devices ? There are three open file STDIN , STDOUT , STERR ? Or whatever ?

Here is definition

int tcsetattr(int fildes, int optional_actions,
    const struct termios *termios_p)
What is fildes parameter refers to ?

The tcsetattr() function sets the parameters associated with the terminal referred to by the open file descriptor fildes

Which descriptor ? Descriptor of opened process file /dev/tty . For example I have four opened files for bash 0 1 2 255. As I can guess 255 is filedescriptor of tty devices ?Okey , but how does 0 1 2 connected to user input/output, if we have opened dev/tty which handles requests. Is this files are connected to this /dev/tty (255) pseudo device ?

Why this should be useful when I am going to fork and send forked process in background ?? What should I do to put process in background ? As I can guess I need to close or open new 0 1 2 file for this process in order not to write in parent input ?? OR I am completely wrong. What is the correct way to send process into background , but not completely lose control of it ? I have read about tcsetpgrp , I understood. The first process connected to the dev/tty devices will be its leader.So terminal group will have same id as the first process ? Am I correct ?

And finally why do we need all this tty now, earlier it was the way of remote connection to computer. But why not to call system (kernel) functions directly ?

I have lack of comprehension... I really need someone help. I WOULD BE VERY GRATEFUL FOR ANY HELP. Please explain for such stupid like.

Last edited by Nitup; 12-06-2014 at 02:24 AM.
Old 12-06-2014, 02:24 AM   #2
LQ Newbie
Registered: Dec 2014
Posts: 13

Original Poster
Rep: Reputation: Disabled
No one can help ,explain this topic ? Or give some good literature to read ?
Old 12-06-2014, 11:18 PM   #3
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,711

Rep: Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279
Personally, I like the Stevens books on UNIX programming...

Your problem is partly caused by history.

Originally, "tty" refers to a physical peripheral using serial lines to a terminal. The serial line used a protocol for synchronizing the terminal with the interface. The ioctl controls were to set/clear various flags in the protocol (RS232) define the speed, number of bits to use, flag control, start bits, stop bits, parity, ready-to-send/clear-to-send (or xon/xoff), modem control signals ... If you want to see what all could be controlled, try the command "stty -a", then look up all the different options. You can also see (though the man page doesn't have much in the way of explanations) the man page on tty_ioctl.

Virtual terminals can ignore nearly all of that as it doesn't apply.

Pseudo terminals work totally differently than virtual terminals (though they are related - both are simulated devices). Pseudo terminals have two parts - a master control half that is used by applications to send/receive character sequences to a terminal half. The terminal half provides the simulation of a physical terminal interface.

Applications like xterm/gnome-terminal/... use the control half so that they can translate the character sequence into a graphical display. The terminal half is used to provide the basic interface to a shell or application that is attached to the device name associated with the simulation of the terminal interface.

Network applications (such as sshd) that provide a simulated terminal environment for remote connections work the same way. In this case, sshd uses the network to forward the character sequence (in both directions), and still provides the terminal emulation. The ssh client uses the terminal attached to read the keyboard/write to the terminal and forward the character stream to the remote server.

A brief slide show on pseudoterminals is at

Use it only as an outline as the details can get quite complicated (the problem is synchronization between input and output).

As for why it is still used - A terminal device is still the simplest interface that works for applications. It has VERY low overhead imposed on the application (all it needs is read/write system calls). All other interfaces are HUGELY complicated.

Last edited by jpollard; 12-06-2014 at 11:23 PM.


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
tcsetattr timing issues SJank Programming 1 06-23-2011 12:27 PM
Terminal Functions For Linux Like Putty or Kitty sampappachan_nyc Linux - Software 2 02-21-2011 10:27 PM
A question about running functions straight off a terminal trist007 Programming 8 12-14-2008 05:33 AM
about using tcsetpgrp chrislam Programming 1 09-22-2007 08:16 AM
tcsetattr() TCSANOW vs. TCSETA GarroteYou Programming 1 05-16-2005 10:45 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:08 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration