{"id":1887,"date":"2015-01-31T10:22:33","date_gmt":"2015-01-31T02:22:33","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=1887"},"modified":"2015-01-31T10:22:33","modified_gmt":"2015-01-31T02:22:33","slug":"linux%e4%b8%ad%e7%9a%84tty%e5%92%8cpts%e7%9a%84%e5%90%ab%e4%b9%89%e4%bb%a5%e5%8f%8a%e5%8c%ba%e5%88%ab","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/1887.html","title":{"rendered":"Linux\u4e2d\u7684tty\u548cpts\u7684\u542b\u4e49\u4ee5\u53ca\u533a\u522b"},"content":{"rendered":"<h5>Linux\u4e2d\u7684tty\u548cpts\u7684\u542b\u4e49\u4ee5\u53ca\u533a\u522b<\/h5>\n<h6>\u7531\u6765\uff1a<\/h6>\n<p>\u5728Linux\u4e0b\u4f7f\u7528w\/who\u547d\u4ee4\u67e5\u770b\u5f53\u524d\u7cfb\u7edf\u4e0a\u6709\u54ea\u4e9b\u4eba\u7684\u65f6\u5019\u7ecf\u5e38\u53ef\u4ee5\u770b\u5230pts\/0\u548cpts\/1\u8fd9\u6837\u7684\u5b57\u773c\uff0c\u4e0a\u7f51\u4e00\u770b\uff0c\u8c8c\u4f3c\u8fd8\u6709tty1\u8fd9\u79cd\u7684\uff0c\u4e8e\u662f\u6211\u5c31\u60f3\u77e5\u9053\u5b83\u4eec\u4e4b\u95f4\u5230\u5e95\u662f\u4e2a\u4ec0\u4e48\u533a\u522b\u3001\u5206\u522b\u53c8\u662f\u4ec0\u4e48\u542b\u4e49\uff1f<\/p>\n<h6>\u641c\u7d22\u5173\u952e\u5b57\uff1a<\/h6>\n<p><a href=\"http:\/\/search.aol.com\/aol\/search?q=linux+tty+pts\" target=\"_blank\">http:\/\/search.aol.com\/aol\/search?q=linux+tty+pts<\/a><\/p>\n<h6>\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff1a<\/h6>\n<p><span style=\"color: #ff0000;\">A tty is a native terminal device, the backend is either hardware or kernel emulated<\/span>.{tty\u5c31\u662f\u4e00\u4e2a\u672c\u5730\u7684\u7ec8\u7aef\u8bbe\u5907\uff0c\u540e\u7aef\u8fde\u7684\u662f\u5b9e\u4f53\u673a\u6216\u6a21\u62df\u5668}(More info can be found in man tty.\u66f4\u8be6\u7ec6\u7684\u5185\u5bb9\u53ef\u4ee5\u67e5\u770btty\u7684manual)<\/p>\n<p><span style=\"color: #ff0000;\">A pty (pseudo terminal device) is a terminal device which is emulated by an other program<\/span> (example: xterm, screen, or ssh are such programs). A pts is the slave part of a pty.{pty\u4e5f\u662f\u4e00\u4e2a\u7ec8\u7aef\u8bbe\u5907\uff0c\u4e0d\u8fc7\u662f\u7531\u5176\u5b83\u7a0b\u5e8f\u6a21\u62df\u51fa\u6765\u7684\uff0c\u6bd4\u5982\uff1axterm\/screen\/ssh\uff1b\u800cpts\u6307\u7684\u5c31\u662f\u5c31\u662fpty\u7684\u4ece\u8bbe\u5907}(More info can be found in man pty.\u66f4\u8be6\u7ec6\u7684\u5185\u5bb9\u53ef\u4ee5\u67e5\u770bpty\u7684manual)<\/p>\n<p>{\u7b80\u800c\u8a00\u4e4b}:<\/p>\n<p>A pty is created by a process through posix_openpt() (which usually opens the special device \/dev\/ptmx), and is constituted by a pair of bidirectional character devices:<\/p>\n<ol>\n<li>The master part, which is the file descriptor obtained by this process through this call, is used to emulate a terminal. After some initialization, the second part can be unlocked with unlockpt(), and the master is used to receive or send characters to this second part (slave).<\/li>\n<li>The slave part, which is anchored in the filesystem as \/dev\/pts\/x (the real name can be obtained by the master through ptsname() ) behaves like a native terminal device (\/dev\/ttyx). In most cases, a shell is started that uses it as a controlling terminal.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h6>\u53c2\u8003\u94fe\u63a5\uff1a<\/h6>\n<ul>\n<li><a href=\"http:\/\/unix.stackexchange.com\/questions\/21280\/difference-between-pts-and-tty\" target=\"_blank\">http:\/\/unix.stackexchange.com\/questions\/21280\/difference-between-pts-and-tty<\/a><\/li>\n<li><a href=\"http:\/\/unix.stackexchange.com\/questions\/60641\/linux-difference-between-dev-console-dev-tty-and-dev-tty0\" target=\"_blank\">http:\/\/unix.stackexchange.com\/questions\/60641\/linux-difference-between-dev-console-dev-tty-and-dev-tty0<\/a><\/li>\n<li><a href=\"http:\/\/unix.stackexchange.com\/questions\/4126\/what-is-the-exact-difference-between-a-terminal-a-shell-a-tty-and-a-con\" target=\"_blank\">http:\/\/unix.stackexchange.com\/questions\/4126\/what-is-the-exact-difference-between-a-terminal-a-shell-a-tty-and-a-con<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Linux\u4e2d\u7684tty\u548cpts\u7684\u542b\u4e49\u4ee5\u53ca\u533a\u522b \u7531\u6765\uff1a \u5728Linux\u4e0b\u4f7f\u7528w\/who\u547d\u4ee4\u67e5\u770b\u5f53\u524d\u7cfb\u7edf\u4e0a\u6709\u54ea\u4e9b\u4eba\u7684\u65f6 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,11],"tags":[458,459,460],"class_list":["post-1887","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-linux","tag-pts","tag-pty","tag-tty"],"views":7774,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/1887","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=1887"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/1887\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=1887"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=1887"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=1887"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}