cons 9.0 KB

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