LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   tcgetattr,tcsetpgrp, tcsetattr and other terminal functions (https://www.linuxquestions.org/questions/linux-newbie-8/tcgetattr-tcsetpgrp-tcsetattr-and-other-terminal-functions-4175527449/)

Nitup 12-05-2014 11:47 AM

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 ,

Quote:

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

Code:

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.

Nitup 12-06-2014 01:24 AM

No one can help ,explain this topic ? Or give some good literature to read ?

jpollard 12-06-2014 10:18 PM

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 http://www.cs.uah.edu/~kkeen/CS590/P...0Terminals.ppt

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.


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