1 .\" Copyright (C) 2002 Andries Brouwer <aeb@cwi.nl>
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" This replaces an earlier man page written by Walter Harms
24 .\" <walter.harms@informatik.uni-oldenburg.de>.
26 .\" Japanese Version Copyright (c) 2004 Yuichi SATO
27 .\" all rights reserved.
28 .\" Translated Wed Sep 8 01:25:01 JST 2004
29 .\" by Yuichi SATO <ysato444@yahoo.co.jp>
31 .TH TTYSLOT 3 2007-11-26 "GNU" "Linux Programmer's Manual"
34 .\"O ttyslot \- find the slot of the current user's terminal in some file
35 ttyslot \- ¥«¥ì¥ó¥È¥æ¡¼¥¶¤ÎüËö¤Î¥¹¥í¥Ã¥È¤ò¥Õ¥¡¥¤¥ë¤«¤éõ¤¹
38 .\"O .BR "#include <unistd.h>" " /* on BSD-like systems, and Linux */"
39 .BR "#include <unistd.h>" " /* BSD ·Ï¤Î¥·¥¹¥Æ¥à¤È Linux ¤Î¾ì¹ç */"
41 .\"O .BR "#include <stdlib.h>" " /* on System V-like systems */"
42 .BR "#include <stdlib.h>" " /* System V ·Ï¤Î¥·¥¹¥Æ¥à¤Î¾ì¹ç */"
44 .B "int ttyslot(void);"
47 .\"O Feature Test Macro Requirements for glibc (see
48 .\"O .BR feature_test_macros (7)):
49 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
50 .RB ( feature_test_macros (7)
56 _BSD_SOURCE || (_XOPEN_SOURCE_EXTENDED && !\ _XOPEN_SOURCE\ >=\ 500)
60 .\"O The legacy function
62 .\"O returns the index of the current user's entry in some file.
65 ¤Ï¡¢¤¢¤ë¥Õ¥¡¥¤¥ë¤Ë½ñ¤«¤ì¤Æ¤¤¤ë¥«¥ì¥ó¥È¥æ¡¼¥¶¤Î¥¨¥ó¥È¥ê¤Î¥¤¥ó¥Ç¥Ã¥¯¥¹¤òÊÖ¤¹¡£
67 .\"O Now "What file?" you ask.
68 .\"O Well, let's first look at some history.
69 ¡Ö¤É¤Î¥Õ¥¡¥¤¥ë¤Ê¤Î¤«¡©¡×¤È¤¤¤¦¼ÁÌ䤬¤¢¤ë¤À¤í¤¦¡£
70 ¤Ç¤Ï¡¢¤Þ¤ººÇ½é¤Ë¤½¤ÎÎò»Ë¤ò¸«¤Æ¤ß¤è¤¦¡£
71 .\"O .SS "Ancient History"
73 .\"O There used to be a file
75 .\"O in Unix V6, that was read by the
77 .\"O program to find out what to do with each terminal line.
80 ¥Õ¥¡¥¤¥ë¤¬»È¤ï¤ì¤Æ¤¤¤¿¡£
82 ¥×¥í¥°¥é¥à¤Ï¡¢¤³¤Î¥Õ¥¡¥¤¥ë¤òÆɤ߹þ¤ß¡¢
83 ³ÆüËö¹Ô¤Ç²¿¤ò¤¹¤Ù¤¤«¤òõ¤¹¡£
84 .\"O Each line consisted of three characters.
85 ³Æ¹Ô¤Ï 3 ʸ»ú¤«¤é¹½À®¤µ¤ì¤Æ¤¤¤ë¡£
86 .\"O The first character was either \(aq0\(aq or \(aq1\(aq,
87 .\"O where \(aq0\(aq meant "ignore".
88 1 ʸ»úÌÜ¤Ï \(aq0\(aq ¤Þ¤¿¤Ï \(aq1\(aq ¤Ç¤¢¤ê¡¢
89 \(aq0\(aq ¤Ï¡Ö̵»ë¤¹¤ë¡×¤³¤È¤òɽ¤¹¡£
90 .\"O The second character denoted the terminal: \(aq8\(aq stood for "/dev/tty8".
91 2 ʸ»úÌܤÏüËö¤ò¼¨¤¹: \(aq8\(aq ¤Ï "/dev/tty8" ¤òɽ¤¹¡£
92 .\"O The third character was an argument to
94 .\"O indicating the sequence of line speeds to try (\(aq\-\(aq was: start trying
96 .\"O Thus a typical line was "18\-".
99 ¤Ø¤Î°ú¤¿ô¤Ç¤¢¤ê¡¢(Àܳ¤ò) »î¤ß¤ë²óÀþ®Å٤νç½ø¤òɽ¤¹
100 (\(aq\-\(aq ¤Ï 110 ¥Ü¡¼¤ÇÀܳ¤Î»î¹Ô¤ò³«»Ï¤¹¤ë¤³¤È¤òɽ¤¹)¡£
101 ¤è¤Ã¤Æ°ìÈÌŪ¤Ê¹Ô¤Ï "18\-" ¤È¤Ê¤ë¡£
102 .\"O A hang on some line was solved by changing the \(aq1\(aq to a \(aq0\(aq,
103 .\"O signaling init, changing back again, and signaling init again.
104 ¤¢¤ë¹Ô¤Ç¥Ï¥ó¥°¤·¤¿¾ì¹ç¤Ï¡¢\(aq1\(aq ¤ò \(aq0\(aq ¤ËÊѹ¹¤·¡¢
105 init ¤Ë¥·¥°¥Ê¥ë¤òÁ÷¤ê¡¢\(aq0\(aq ¤ò \(aq1\(aq ºÆÅÙ¤ËÊѹ¹¤·¡¢
106 init ¤ËºÆÅÙ¥·¥°¥Ê¥ë¤òÁ÷¤ë¤³¤È¤Ç²ò·è¤¹¤ë¡£
108 .\"O In Unix V7 the format was changed: here the second character
109 .\"O was the argument to
111 .\"O indicating the sequence of line speeds to try (\(aq0\(aq was: cycle through
112 .\"O 300-1200-150-110 baud; \(aq4\(aq was for the on-line console DECwriter)
113 .\"O while the rest of the line contained the name of the tty.
114 .\"O Thus a typical line was "14console".
115 Unix V7 ¤Ç¤Ï¥Õ¥©¡¼¥Þ¥Ã¥È¤¬Êѹ¹¤µ¤ì¤¿:
118 ¤Î°ú¤¿ô¤È¤Ê¤ê¡¢(Àܳ¤ò) »î¤ß¤ë²óÀþ®Å٤νç½ø¤òɽ¤¹¤è¤¦¤Ë¤Ê¤ê
119 (\(aq0\(aq ¤Ï 300-1200-150-110 ¤ò·«¤êÊÖ¤¹¤³¤È¤òɽ¤·¡¢
120 \(aq4\(aq ¤Ï¥ª¥ó¥é¥¤¥ó¥³¥ó¥½¡¼¥ë DECwriter ¤òɽ¤¹)¡¢
121 ¹Ô¤Î»Ä¤ê (¤Îʸ»ú) ¤ÏüËö̾¤È¤Ê¤Ã¤¿¡£
122 ¤è¤Ã¤Æ¡¢°ìÈÌŪ¤Ê¹Ô¤Ï "14console" ¤È¤Ê¤ë¡£
124 .\"O Later systems have more elaborate syntax.
125 ¸å¼Ô¤Î¥·¥¹¥Æ¥à¤Î½ñ¼°¤Ï¡¢¤è¤êÀº¹ª¤Ç¤¢¤ë¡£
126 .\"O System V-like systems have
129 System V ·Ï¤Î¥·¥¹¥Æ¥à¤Ç¤Ï¡¢Âå¤ï¤ê¤Ë
132 .\"O .SS "Ancient History (2)"
134 .\"O On the other hand, there is the file
136 .\"O listing the people currently logged in.
137 .\"O It is maintained by
139 °ìÊý¡¢¸½ºß¥í¥°¥¤¥ó¤·¤Æ¤¤¤ë¿Í¤ò¥ê¥¹¥È¤¹¤ë¥Õ¥¡¥¤¥ë
144 ¤Ë¤è¤Ã¤Æ´ÉÍý¤µ¤ì¤Æ¤¤¤ë¡£
145 .\"O It has a fixed size, and the appropriate index in the file was
150 .\"O call to find the number of the line in
152 .\"O (counting from 1).
153 ¤³¤Î¥Õ¥¡¥¤¥ë¤Ï¸ÇÄꤵ¤ì¤¿¥µ¥¤¥º¤Ç¤¢¤ê¡¢¥Õ¥¡¥¤¥ëÆâ¤ÎŬÀڤʥ¤¥ó¥Ç¥Ã¥¯¥¹¤Ï¡¢
160 ¤Ë¤ª¤±¤ë¹ÔÈÖ¹æ¤ò¸«¤Ä¤±¤ë (¹ÔÈÖ¹æ¤Ï 1 ¤«¤é¿ô¤¨¤ë)¡£
161 .\"O .SS "The semantics of ttyslot"
163 .\"O Thus, the function
165 .\"O returns the index of the controlling terminal of the calling process
168 .\"O and that is (usually) the same as the index of the entry for the
169 .\"O current user in the file
175 ¤Ë¤ª¤±¤ë¸Æ¤Ó½Ð¤·¸µ¤Î¥×¥í¥»¥¹¤ÎÀ©¸æüËö¤Î¥¤¥ó¥Ç¥Ã¥¯¥¹¤òÊÖ¤¹¡£
178 ¤Ë¤ª¤±¤ë¥«¥ì¥ó¥È¥æ¡¼¥¶¤Î¥¨¥ó¥È¥ê¤Î¥¤¥ó¥Ç¥Ã¥¯¥¹¤È (Ä̾ï¤Ï) Åù¤·¤¤¡£
179 .\"O BSD still has the
181 .\"O file, but System V-like systems do not, and hence cannot refer to it.
184 ¥Õ¥¡¥¤¥ë¤¬¤¢¤ë¤¬¡¢System V ·Ï¤Î¥·¥¹¥Æ¥à¤Ë¤Ï¤Ê¤¤¤Î¤Ç¡¢
185 ¤³¤Î¥Õ¥¡¥¤¥ë¤ò»²¾È¤¹¤ë¤³¤È¤Ï¤Ç¤¤Ê¤¤¡£
186 .\"O Thus, on such systems the documentation says that
188 .\"O returns the current user's index in the user accounting data base.
189 ¤è¤Ã¤Æ¡¢¤½¤Î¤è¤¦¤Ê¥·¥¹¥Æ¥à¤Ç¤Ï
191 ¤Ï¥«¥ì¥ó¥È¥æ¡¼¥¶¤Î¥æ¡¼¥¶¥¢¥«¥¦¥ó¥È¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë¤ª¤±¤ë¥¤¥ó¥Ç¥Ã¥¯¥¹¤òÊÖ¤¹¡×
192 ¤È¥É¥¥å¥á¥ó¥È¤Ë½ñ¤«¤ì¤Æ¤¤¤ë¡£
193 .\"O .SH "RETURN VALUE"
195 .\"O If successful, this function returns the slot number.
196 À®¸ù¤·¤¿¾ì¹ç¡¢¤³¤Î´Ø¿ô¤Ï¥¹¥í¥Ã¥ÈÈÖ¹æ¤òÊÖ¤¹¡£
197 .\"O On error (e.g., if none of the file descriptors 0, 1 or 2 is
198 .\"O associated with a terminal that occurs in this data base)
199 .\"O it returns 0 on Unix V6 and V7 and BSD-like systems,
200 .\"O but \-1 on System V-like systems.
202 (Î㤨¤Ð¡¢¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿ 0, 1, 2 ¤Î²¿¤ì¤â
203 ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë¤¢¤ëüËö¤Ë´ØÏ¢¤Å¤±¤é¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç)¡¢
204 Unix V6, V7, BSD ·Ï¤Î¥·¥¹¥Æ¥à¤Ï 0 ¤òÊÖ¤¹¤¬¡¢
205 System V ·Ï¤Î¥·¥¹¥Æ¥à¤Ï -1 ¤òÊÖ¤¹¡£
206 .\"O .SH "CONFORMING TO"
208 .\"O SUSv1; marked as LEGACY in SUSv2; removed in POSIX.1-2001.
209 .\"O SUSv2 requires \-1 on error.
210 SUSv1¡£SUSv2 ¤Ç¤Ï¡Ö²áµî¤Î̾»Ä (LEGACY)¡×¤È°ÌÃÖÉÕ¤±¤é¤ì¤Æ¤¤¤ë¡£
211 POSIX.1-2001 ¤Çºï½ü¤µ¤ì¤¿¡£
212 SUSv2 ¤Ç¤Ï¥¨¥é¡¼»þ¤Ë \-1 ¤òÊÖ¤¹¤³¤È¤¬Í׵ᤵ¤ì¤Æ¤¤¤ë¡£
215 .\"O The utmp file is found various places on various systems, such as
217 .\"O .IR /var/adm/utmp ,
218 .\"O .IR /var/run/utmp .
219 utmp ¥Õ¥¡¥¤¥ë¤ÏÍÍ¡¹¤Ê¥·¥¹¥Æ¥à¤Ç
223 ¤Î¤è¤¦¤Ë¤¤¤í¤¤¤í¤Ê¾ì½ê¤Ë¤¢¤ë¡£
225 .\"O The glibc2 implementation of this function reads the file
226 .\"O .BR _PATH_TTYS ,
230 .\"O It returns 0 on error.
231 ¤³¤Î´Ø¿ô¤Î glibc2 ¤Ë¤ª¤±¤ë¼ÂÁõ¤Ç¤Ï¡¢¥Õ¥¡¥¤¥ë
236 ¤Ë¤ª¤¤¤Æ "/etc/ttys" ¤ÈÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£
237 ¥¨¥é¡¼¤Î¾ì¹ç¡¢0 ¤òÊÖ¤¹¡£
238 .\"O Since Linux systems do not usually have "/etc/ttys", it will
239 .\"O always return 0.
240 Linux ¥·¥¹¥Æ¥à¤Ë¤ÏÄ̾ï "/etc/ttys" ¤¬¤Ê¤¤¤Î¤Ç¡¢¾ï¤Ë 0 ¤òÊÖ¤¹¡£
243 .\"O .IR fttyslot ( fd ).
249 .\"O .\" .BR ttyslot ()
250 .\"O .\" appeared in Unix V7.
252 .\" ¤Ï Unix V7 ¤ËÅо줷¤¿¡£