cons 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. .TH CONS 3
  2. .SH NAME
  3. cons \- console, clocks, process/process group ids, user, null, reboot, etc.
  4. .SH SYNOPSIS
  5. .nf
  6. .B bind #c /dev
  7. .B /dev/bintime
  8. .B /dev/cons
  9. .B /dev/consctl
  10. .B /dev/cputime
  11. .B /dev/drivers
  12. .B /dev/hostdomain
  13. .B /dev/hostowner
  14. .B /dev/kprint
  15. .B /dev/null
  16. .B /dev/osversion
  17. .B /dev/pgrpid
  18. .B /dev/pid
  19. .B /dev/ppid
  20. .B /dev/random
  21. .B /dev/reboot
  22. .B /dev/swap
  23. .B /dev/sysname
  24. .B /dev/sysstat
  25. .B /dev/time
  26. .B /dev/user
  27. .B /dev/zero
  28. .fi
  29. .SH DESCRIPTION
  30. The console device serves a one-level directory
  31. giving access to the console and
  32. miscellaneous information.
  33. .PP
  34. Reading the
  35. .B cons
  36. file returns characters typed on the keyboard.
  37. Normally, characters are buffered to enable erase and kill processing.
  38. A control-U,
  39. .LR ^U ,
  40. typed at the keyboard
  41. .I kills
  42. the current input line (removes all characters
  43. from the buffer of characters
  44. not yet read via
  45. .BR cons ),
  46. and a backspace
  47. .I erases
  48. the previous non-kill, non-erase character from the input buffer.
  49. Killing and erasing only delete characters back to, but not including,
  50. the last newline.
  51. Characters typed at the keyboard actually produce 16-bit runes (see
  52. .IR utf (6)),
  53. but the runes are translated into the variable-length
  54. .SM UTF
  55. encoding (see
  56. .IR utf (6))
  57. before putting them into the buffer.
  58. A
  59. .IR read (2)
  60. of length greater than zero causes the process to wait until a
  61. newline or a
  62. .L ^D
  63. ends the buffer, and then returns as much of the buffer as the argument
  64. to
  65. .B read
  66. allows, but only up to one complete line.
  67. A terminating
  68. .L ^D
  69. is not put into the buffer.
  70. If part of the line remains, the next
  71. .B read
  72. will return bytes from that remainder and not part of any new line
  73. that has been typed since.
  74. .PP
  75. If
  76. the string
  77. .B rawon
  78. has been written to the
  79. .B consctl
  80. file and the file is still open,
  81. .B cons
  82. is in
  83. .IR "raw mode" :
  84. characters are not echoed as they are typed,
  85. backspace and
  86. .L ^D
  87. are not treated specially,
  88. and characters are available to
  89. .I read
  90. as soon as they are typed.
  91. Ordinary mode is reentered when
  92. .B rawoff
  93. is written to
  94. .B consctl
  95. or this file is closed.
  96. .PP
  97. A
  98. .I write
  99. (see
  100. .IR read (2))
  101. to
  102. .B cons
  103. causes the characters to be printed on the console screen.
  104. .PP
  105. The
  106. .B osversion
  107. file contains a textual representation of the operating system's version and parameters.
  108. At the moment, it contains one field: the 9P protocol version, currently
  109. .BR 2000 .
  110. .PP
  111. The
  112. .B kprint
  113. file may be read to receive a copy of the data written
  114. to the console by the kernel's print statements or by processes
  115. writing to
  116. .BR /dev/cons .
  117. Only data written after the file is opened is available.
  118. If the machine's console is a serial line, the data is sent both to the
  119. console and to
  120. .BR kprint ;
  121. if its console is a graphics screen, the data is sent either to the
  122. display or to
  123. .BR kprint ,
  124. but not both.
  125. (It is advisable not to open
  126. .B kprint
  127. on terminals until you have started
  128. .IR rio (1).)
  129. .PP
  130. The
  131. .B null
  132. file throws away anything written to it
  133. and always returns zero bytes when read.
  134. .PP
  135. The
  136. .B zero
  137. file is a read-only file that produces an infinite stream of zero-valued bytes when read.
  138. .PP
  139. The
  140. .B drivers
  141. file contains, one per line, a listing of the drivers configured in the kernel, in the format
  142. .IP
  143. .EX
  144. #c cons
  145. .EE
  146. .PP
  147. The
  148. .B hostdomain
  149. file contains the name of the authentication domain that
  150. this host belongs to; see
  151. .IR authsrv (6).
  152. Only the user named in
  153. .B /dev/hostowner
  154. may write this.
  155. .PP
  156. The
  157. .B hostowner
  158. file contains the name of the user that owns the console device files.
  159. The hostowner also has group permissions for any local devices.
  160. .PP
  161. Reads from
  162. .B random
  163. return a stream of random numbers. The numbers are
  164. generated by a low priority kernel process that loops
  165. incrementing a variable. Each clock tick the variable
  166. is sampled and, if it has changed sufficiently, the last
  167. few bits are appended to a buffer. This process is inefficient
  168. at best producing at most a few hundred bits a second.
  169. Therefore,
  170. .B random
  171. should be treated as a seed to
  172. pseudo-random number generators which can produce a faster
  173. rate stream.
  174. .PP
  175. Writing the string
  176. .B reboot
  177. to
  178. .B reboot
  179. causes the system to shutdown and, if
  180. possible, restart.
  181. Writing the string
  182. .B reboot
  183. .I kernelpath
  184. loads the named kernel image and restarts,
  185. preserving the kernel configuration in
  186. .BR #ec ,
  187. except that the
  188. .B bootfile
  189. variable is set to
  190. .IR kernelpath .
  191. Only the host
  192. owner has the ability to open this file.
  193. .PP
  194. .B Bintime
  195. is a binary interface that provides
  196. the same information as
  197. .B time
  198. .RI ( q.v. ),
  199. in binary form,
  200. and also controls clock frequency and clock trim.
  201. All integers read or written from
  202. .B bintime
  203. are in big endian order.
  204. Unlike the other files, reads and writes do not affect
  205. the offset. Therefore, there is no need for a seek
  206. back to zero between subsequent accesses.
  207. A read of
  208. .B bintime
  209. returns 24 bytes, three 8 byte numbers, representing nanoseconds
  210. since start of epoch, clock ticks, and clock frequency.
  211. .PP
  212. A write to
  213. .B bintime
  214. is a message with one of 3 formats:
  215. .IP "\f5n\fP<8-byte \f2time\fP>" 1.2i
  216. set the nanoseconds since epoch to the given
  217. .IR time .
  218. .IP "\f5d\fP<8-byte \f2delta\fP><4-byte \f2period\fP>" 1.2i
  219. trim the nanoseconds since epoch by
  220. .I delta
  221. over the next
  222. .I period
  223. seconds.
  224. .IP "\f5f\fP<8-byte \f2freq\fP>" 1.2i
  225. Set the frequency for interpreting clock ticks to be
  226. .I freq
  227. ticks per second.
  228. .PP
  229. The rest of the files contain (mostly) read-only strings.
  230. Each string has a fixed length: a
  231. .IR read (2)
  232. of more than that gives a result of that fixed length (the result does not
  233. include a terminating zero byte);
  234. a
  235. .I read
  236. of less than that length leaves the file offset so the
  237. rest of the string (but no more) will be read the next time.
  238. To reread the file without closing it,
  239. .I seek
  240. must be used to reset the offset.
  241. When the file contains numeric data
  242. each number is formatted in decimal.
  243. If the binary number fits in 32 bits, it is formatted as an
  244. 11 digit decimal number with
  245. leading blanks and one trailing blank; totaling 12 bytes.
  246. Otherwise, it
  247. is formatted as 21 digit decimal numbers with leading blanks and one
  248. trailing blank; totaling 22 bytes.
  249. .PP
  250. The
  251. .B cputime
  252. file holds six 32-bit numbers, containing the time in milliseconds
  253. that the current process has spent in user mode, system calls,
  254. real elapsed time, and then the time spent, by exited children and their descendants,
  255. in user mode, system calls, and real elapsed time.
  256. .PP
  257. The
  258. .B time
  259. file holds one 32-bit number representing the seconds since start of epoch
  260. and three 64-bit numbers, representing nanoseconds since
  261. start of epoch, clock ticks, and clock frequency.
  262. .PP
  263. A write of a decimal number to
  264. .B time
  265. will set the seconds since epoch.
  266. .PP
  267. The
  268. .B sysname
  269. file holds the textual name of the machine, e.g.
  270. .BR kremvax ,
  271. if known.
  272. .PP
  273. The
  274. .B sysstat
  275. file holds 8 numbers:
  276. processor number, context switches, interrupts, system calls, page faults,
  277. TLB faults, TLB purges, and load average.
  278. The load average is in units of milli-CPUs and is decayed over time;
  279. the others are total counts from boot time.
  280. If the machine is a multiprocessor,
  281. .B sysstat
  282. holds one line per processor.
  283. Writing anything to
  284. .B sysstat
  285. resets all of the counts on all processors.
  286. .PP
  287. The
  288. .B swap
  289. device holds a string of the form
  290. .IP
  291. .IB m1 / m2
  292. .B memory
  293. .IB s1 / s2
  294. .B swap
  295. .PP
  296. These give, for each of
  297. internal memory and the swapping area,
  298. the number of pages used and the total available.
  299. These numbers are not blank padded.
  300. To turn on swapping, write to
  301. .B swap
  302. the textual file descriptor number of a file or device on which to swap.
  303. See
  304. .IR swap (8).
  305. .PP
  306. The other files served by the
  307. .I cons
  308. device are all single numbers:
  309. .TP 10
  310. .B pgrpid
  311. process group number
  312. .TP
  313. .B pid
  314. process number
  315. .TP
  316. .B ppid
  317. parent's process number
  318. .SH SEE ALSO
  319. .IR draw (3),
  320. .IR keyboard (6),
  321. .IR authsrv (6),
  322. .IR utf (6),
  323. .IR swap (8)
  324. .SH SOURCE
  325. .B /sys/src/9/port/devcons.c
  326. .SH BUGS
  327. For debugging, two control-T's followed by a letter
  328. generate console output and manage debugging:
  329. .L ^T^Td
  330. toggles whether the console debugger will be run if the system fails.
  331. .L ^T^TD
  332. starts the console debugger immediately.
  333. .L ^T^Tk
  334. kills the largest process; use with care.
  335. .L ^T^Tp
  336. prints data about processes.
  337. .L ^T^Tq
  338. prints the run queue for processor 0.
  339. .L ^T^Ts
  340. prints the kernel stack.
  341. .L ^T^Tx
  342. prints data about kernel memory allocation.
  343. .PP
  344. The system can be rebooted by typing
  345. .LR ^T^Tr .