How can I create a loop between two TTYs?

随声附和 提交于 2019-12-11 03:33:18

问题


Every Hello has a response. Second TTY will send a hello to the sender TTY and vice versa:

echo 'echo hello > /dev/pts/1' > /dev/pts/0

The 1st receiver should send "hello" to the original sender, but it does not. What is wrong?

[Clarification] I have two shells running. /dev/pts/1 is the initial sender.


回答1:


When you send your echo command to /dev/pts/0 you are literally just sending the output of that echo to the other TTY's output - you are not sending it to the other TTY's input buffers. Therefore your nested echo command will simply be displayed on the other TTY, but not executed.

There is an ioctl() call TIOCSTI which can be used to fake input on another TTY, but only if you have "write" permission to that other TTY.

Many years ago I recall that some friends and I discovered holes on some versions of UNIX which didn't correctly enforce the security permissions on TIOCSTI. If root had left a terminal logged in somewhere it was possible to make the root user's terminal type in commands on your behalf...



来源:https://stackoverflow.com/questions/513908/how-can-i-create-a-loop-between-two-ttys

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!