From: Marc R. <re...@gm...> - 2023-08-05 10:59:45
|
Hi Leslie, once again, when you redirect a process (as the command stage does), that process is not connected to a tty anymore, as pipe 'command tty | console' says. That is why the pipe 'command stty --all | console' has a correct empty output. When using a specific device with -F, you are interrogating the characteristics of that device, not necessarily the terminal or console you are running in. Linux has two types of TTYs, physical and pseudo terminals. TTY comes from teletype, from the old days where people interfaced with computers through physical wires. Don't confuse 'terminal' with the terminal application. The stty command does not only allow to collect the characteristics of a TTY, but also allows to change them. Consider this: $ ps axo user,tty,pid,comm | grep bash xxxxxx pts/0 7644 bash xxxxxx tty3 30797 bash xxxxxx pts/1 34414 bash I have three bash programs running, one connected to a 'real' TTY /dev/tty3, started from the console prompt Ctrl-Alt-F3. Two other bash programs are started from the gnome terminal program, and are connected to /dev/pts/0 and /dev/pts/1. $ pipe 'command ps | cons' PID TTY TIME CMD 7644 pts/0 00:00:00 bash 42258 pts/0 00:00:05 java 42289 pts/0 00:00:00 ps The pipeline stages are running as children of process 7644, connected to /dev/pts/0. $ pipe 'command stty --all -F /dev/pts/1 | cons' speed 38400 baud; rows 30; columns 96; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = <undef>; discard = <undef>; min = 1; time = 0; -parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl ixon -ixoff -iuclc -ixany -imaxbel iutf8 opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig -icanon iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc Collected tty specs of sibling bash process 34414, connected to /dev/pts/1 $ pipe 'command stty cols 20 -F /dev/pts/1 | cons' Changed number of columns of /dev/pts/1 (bash process 34414) $ pipe 'command stty --all -F /dev/pts/1 | cons' speed 38400 baud; rows 30; columns 20; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = <undef>; discard = <undef>; min = 1; time = 0; -parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl ixon -ixoff -iuclc -ixany -imaxbel iutf8 opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig -icanon iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc Indeed, number of columns changed. $ pipe 'command stty --all -F /dev/pts/0 | cons' speed 38400 baud; rows 30; columns 120; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0; -parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel iutf8 opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc Number of columns of /dev/pts/0 (i.e where parent bash process is connected to) is unchanged. If you need to know the number of rows of the terminal where the pipelines script is running, you need to know which TTY the parent process is connected to. And it could be that that parent process does not have a TTY, for example when it's started as a daemon, in which case it will produce an empty stty --all output.. More reading about the old and newer days : https://itsfoss.com/what-is-tty-in-linux/ https://www.linusakesson.net/programming/tty/ Marc |