proc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. .TH PROC 3
  2. .SH NAME
  3. proc \- running processes
  4. .SH SYNOPSIS
  5. .nf
  6. .B bind #p /proc
  7. .sp 0.3v
  8. .B /proc/trace
  9. .BI /proc/ n /args
  10. .BI /proc/ n /core
  11. .BI /proc/ n /ctl
  12. .BI /proc/ n /fd
  13. .BI /proc/ n /fpregs
  14. .BI /proc/ n /kregs
  15. .BI /proc/ n /mem
  16. .BI /proc/ n /note
  17. .BI /proc/ n /noteid
  18. .BI /proc/ n /notepg
  19. .BI /proc/ n /ns
  20. .BI /proc/ n /proc
  21. .BI /proc/ n /profile
  22. .BI /proc/ n /regs
  23. .BI /proc/ n /segment
  24. .BI /proc/ n /status
  25. .BI /proc/ n /text
  26. .BI /proc/ n /wait
  27. \&...
  28. .fi
  29. .SH DESCRIPTION
  30. The
  31. .I proc
  32. device serves a two-level directory structure.
  33. The first level contains the
  34. .B trace
  35. file (see below) and numbered directories
  36. corresponding to pids of live processes;
  37. each such directory contains a set of files
  38. representing the corresponding process.
  39. .PP
  40. The
  41. .B mem
  42. file contains the current memory image of the process.
  43. A read or write at offset
  44. .IR o ,
  45. which must be a valid virtual address,
  46. accesses bytes from address
  47. .IR o
  48. up to the end of the memory segment containing
  49. .IR o .
  50. Kernel virtual memory, including the kernel stack for the process and
  51. saved user registers (whose addresses are machine-dependent),
  52. can be accessed through
  53. .BR mem .
  54. Writes are permitted only while the process is in the
  55. .B Stopped
  56. state and only to user addresses or registers.
  57. .PP
  58. The read-only
  59. .B core
  60. file contains the AC number for the process, or 0 if the process is at a TC.
  61. .PP
  62. The read-only
  63. .B proc
  64. file contains the kernel per-process
  65. structure.
  66. Its main use is to recover the kernel stack and program counter
  67. for kernel debugging.
  68. .PP
  69. The files
  70. .BR regs ,
  71. .BR fpregs ,
  72. and
  73. .BR kregs
  74. hold representations of the user-level registers, floating-point registers,
  75. and kernel registers in machine-dependent form.
  76. The
  77. .B kregs
  78. file is read-only.
  79. .PP
  80. The read-only
  81. .B fd
  82. file lists the open file descriptors of the process.
  83. The first line of the file is its current directory; subsequent lines list, one per line,
  84. the open files, giving the decimal file descriptor number; whether the file is open for read
  85. .RB ( r ),
  86. write,
  87. .RB ( w ),
  88. or both
  89. .RB ( rw );
  90. the type, device number, and qid of the file; its I/O unit (the amount of data
  91. that may be transferred on the file as a contiguous piece; see
  92. .IR iounit (2)),
  93. its I/O offset; and its name at the time it was opened.
  94. .PP
  95. The read-only
  96. .B ns
  97. file contains a textual representation of the process's file name space, in the format of
  98. .IR namespace (6)
  99. accepted by
  100. .B newns
  101. (see
  102. .IR auth (2)).
  103. The last line of the file identifies the current working directory of the process, in the form of a
  104. .B cd
  105. command
  106. (see
  107. .IR rc (1)).
  108. The information in this file is based on the names files had when the name space was assembled,
  109. so the names it contains may be inaccessible if the files have been subsequently renamed or rearranged.
  110. .PP
  111. The read-only
  112. .B segment
  113. file contains a textual display of the memory segments
  114. attached to the process. Each line has multiple fields:
  115. the type of segment (\c
  116. .BR Stack ,
  117. .BR Text ,
  118. .BR Data ,
  119. .BR Bss ,
  120. etc.); one-letter flags such as
  121. .B R
  122. for read-only, if any;
  123. starting virtual address, in hexadecimal;
  124. ending virtual address, and reference count.
  125. .PP
  126. The read-only
  127. .B status
  128. file contains a string with twelve fields, each followed by a space.
  129. The fields are:
  130. .IP \-
  131. the process name and user name, each 27 characters left justified
  132. .IP \-
  133. the process state, 11 characters left justified (see
  134. .IR ps (1))
  135. .IP \-
  136. the six 11-character numbers also held in the process's
  137. .B #c/cputime
  138. file
  139. .IP \-
  140. the amount of memory used by the process, except its stack,
  141. in units of 1024 bytes
  142. .IP \-
  143. the base and current scheduling priority, each 11 character numbers
  144. .IP \-
  145. the number of traps for the process
  146. .IP \-
  147. the number of system calls made by the process
  148. .IP \-
  149. the number of inter-core calls made by the process.
  150. .PP
  151. The read-only
  152. .B args
  153. file contains the arguments of the program when it was created by
  154. .IR exec (2).
  155. If the program was not created by
  156. .BR exec ,
  157. such as by
  158. .IR fork (2),
  159. its
  160. .B args
  161. file will be empty.
  162. The format of the file is a list of quoted strings suitable for
  163. .BR tokenize ;
  164. see
  165. .IR getfields (2).
  166. .PP
  167. The
  168. .B text
  169. file is a pseudonym for the file
  170. from which the process was executed;
  171. its main use is to recover the symbol table of the process.
  172. .PP
  173. The
  174. .B wait
  175. file may be read to recover
  176. records from the exiting children of the process in the format of
  177. .B await
  178. (see
  179. .IR wait (2)).
  180. If the process has no extant children, living or exited,
  181. a read of
  182. .B wait
  183. will block.
  184. It is an error for a process to attempt to read its own
  185. .B wait
  186. file when it has no children.
  187. When a process's
  188. .B wait
  189. file is being read,
  190. the process will draw an error
  191. if it attempts an
  192. .B await
  193. system call; similarly, if a process is in an
  194. .B await
  195. system call, its
  196. .B wait
  197. file cannot be read by any process.
  198. .PP
  199. The read-only
  200. .B profile
  201. file contains the instruction frequency count information used for multiprocess profiling; see
  202. .B tprof
  203. in
  204. .IR prof (1).
  205. The information is gleaned by sampling the program's user-level program counter
  206. at interrupt time.
  207. .PP
  208. Strings written to the
  209. .B note
  210. file will be posted as a note to the process
  211. (see
  212. .IR notify (2)).
  213. The note should be less than
  214. .B ERRLEN-1
  215. characters long;
  216. the last character is reserved for a terminating NUL character.
  217. A read of at least
  218. .B ERRLEN
  219. characters will retrieve the oldest note posted to the
  220. process and prevent its delivery to the process.
  221. The
  222. .B notepg
  223. file is similar, but the note will be delivered to all the
  224. processes in the target process's
  225. .I note group
  226. (see
  227. .IR fork (2)).
  228. However, if the process doing the write is in the group,
  229. it will not receive the note.
  230. The
  231. .B notepg
  232. file is write-only.
  233. .PP
  234. The textual
  235. .B noteid
  236. file may be read to recover an integer identifying the note group of the process
  237. (see
  238. .B RFNOTEG
  239. in
  240. .IR fork (2)).
  241. The file may be written to cause the process to change to another note group,
  242. provided the group exists and is owned by the same user.
  243. .PP
  244. The file
  245. .B /proc/trace
  246. can be opened once and read to see trace events from processes that have
  247. had the string
  248. .B trace
  249. written to their
  250. .B ctl
  251. file.
  252. Each event produces, in native machine format, the
  253. .IR pid ,
  254. a
  255. .IR type ,
  256. and a
  257. .I "time stamp"
  258. (see
  259. .B /sys/include/trace.h
  260. and
  261. .BR /sys/src/cmd/trace.c ).
  262. .
  263. .SS Control messages
  264. Textual messages written to the
  265. .B ctl
  266. file control the execution of the process.
  267. Some require that the process is in a particular state
  268. and return an error if it is not.
  269. .TP 10n
  270. .B stop
  271. Suspend execution of the process, putting it in the
  272. .B Stopped
  273. state.
  274. .TP 10n
  275. .B start
  276. Resume execution of a
  277. .B Stopped
  278. process.
  279. .TP 10n
  280. .B waitstop
  281. Do not affect the process directly but, like all other messages ending with
  282. .BR stop ,
  283. block the process writing the
  284. .B ctl
  285. file until the target process is in the
  286. .B Stopped
  287. state or exits.
  288. Also like other
  289. .B stop
  290. control messages,
  291. if the target process would receive a note while the message is pending,
  292. it is instead stopped and the debugging process is resumed.
  293. .TP 10n
  294. .B startstop
  295. Allow a
  296. .B Stopped
  297. process to resume, and then do a
  298. .B waitstop
  299. action.
  300. .TP 10n
  301. .B hang
  302. Set a bit in the process so that,
  303. when it completes an
  304. .IR exec (2)
  305. system call, it will enter the
  306. .B Stopped
  307. state before returning to user mode.
  308. This bit is inherited across
  309. .IR fork (2)
  310. and
  311. .IR exec (2).
  312. .TP 10n
  313. .B "close\ \fIn
  314. Close file descriptor
  315. .I n
  316. in the process.
  317. .TP 10n
  318. .B closefiles
  319. Close all open file descriptors in the process.
  320. .TP 10n
  321. .B nohang
  322. Clear the hang bit.
  323. .TP 10n
  324. .B noswap
  325. Don't allow this process to be swapped out. This should
  326. be used carefully and sparingly or the system could run
  327. out of memory. It is meant for processes that can't be
  328. swapped, like the ones implementing the swap device and for
  329. processes containing sensitive data.
  330. .TP 10n
  331. .B kill
  332. Kill the process the next time it crosses the user/kernel boundary.
  333. .TP 10n
  334. .B private
  335. Make it impossible to read the process's user memory.
  336. This property is inherited on fork, cleared on
  337. .IR exec (2),
  338. and is not otherwise resettable.
  339. .TP 10n
  340. .B "pri\ \fIn
  341. Set the base priority for the process to the integer
  342. .IR n .
  343. .TP 10n
  344. .B "wired\ \fIn
  345. Wire the process to processor
  346. .IR n .
  347. .TP 10n
  348. .B "core\ \fIn
  349. Send the process to AC number
  350. .IR n ,
  351. if
  352. .I n
  353. is greater than zero. Send it back to a TC if
  354. .I n
  355. is zero. Send the process to any AC if
  356. .I n
  357. is less than zero.
  358. .TP 10n
  359. .B trace
  360. Without an argument, toggle trace event generation for this process into
  361. .B /proc/trace
  362. (see below).
  363. With a zero argument, tracing for the proc is turned off, with a non-zero numeric
  364. argument, it is turned on.
  365. .TP 10n
  366. .B "period\ \fInu
  367. Set the real-time scheduling period of the process to
  368. .IR nu ,
  369. where
  370. .I n
  371. is an optionally signed number containing an optional decimal point and
  372. .I u
  373. is one of
  374. .BR s ,
  375. .BR ms ,
  376. .BR us ,
  377. .BR µs ,
  378. .BR ns ,
  379. or
  380. empty. The time is interpreted, respectively, as
  381. .IR seconds ,
  382. .IR milliseconds ,
  383. .IR microseconds ,
  384. .IR microseconds ,
  385. .IR nanoseconds ,
  386. or, in the case of an absent units specifier, as
  387. .IR nanoseconds .
  388. If the time specifier is signed, it is interpreted as an increment or decrement
  389. from a previously set value. See also the
  390. .B admit
  391. command below.
  392. .TP 10n
  393. .B "deadline\ \fInu
  394. Set the real-time deadline interval of the process to
  395. .IR nu ,
  396. where
  397. .I n
  398. and
  399. .I u
  400. are interpreted as for
  401. .B period
  402. above.
  403. .TP 10n
  404. .B "cost\ \fInu
  405. Set the real-time cost (maximum CPU time per period) of the process to
  406. .IR nu ,
  407. where
  408. .I n
  409. and
  410. .I u
  411. are interpreted as for
  412. .B period
  413. above.
  414. .TP 10n
  415. .B "sporadic
  416. Use sporadic scheduling for the real-time process. The description of the
  417. .B admit
  418. command below contains further details.
  419. .TP 10n
  420. .B "yieldonblock
  421. Make the real-time process yield on blocking I/O.
  422. The description of the
  423. .B admit
  424. command below contains further details.
  425. .TP 10n
  426. .B "admit
  427. Given real-time
  428. .IR period ,
  429. .I deadline
  430. and
  431. .I cost
  432. are set (an unset
  433. .I deadline
  434. will set
  435. .I deadline
  436. to
  437. .IR period ),
  438. perform a schedulability test and start scheduling the process as a real-time
  439. process if the test succeeds. If the test fails, the
  440. .B write
  441. will fail with error set to the reason for failure.
  442. .TP 10n
  443. .B event
  444. Add a user event to the
  445. .B /proc/trace
  446. file.
  447. .PD
  448. .
  449. .SS Real-time scheduling
  450. .I Real-time
  451. processes are periodically
  452. .IR released ,
  453. giving them a higher priority than non-real-time processes until they either
  454. give up the processor voluntarily, they exhaust their CPU allocation, or they reach their
  455. .IR deadline .
  456. The moment of release is dictated by the
  457. .I period
  458. and whether the process is
  459. .I sporadic
  460. or not.
  461. Non-sporadic processes are called
  462. .I periodic
  463. and they are released precisely at intervals of their period (but periods can be skipped
  464. if the process blocks on I/O).
  465. Sporadic processes are released whenever they become
  466. runnable (after being blocked by
  467. .IR sleep ()
  468. or I/O), but always at least an interval of
  469. .I period
  470. after the previous release.
  471. .PP
  472. The
  473. .I deadline
  474. of a real-time process specifies that the process must complete within the first
  475. .I deadline
  476. seconds of its
  477. .IR period .
  478. The dealine must be less than or equal to the period.
  479. If it is not specified, it is set to the period.
  480. .PP
  481. The
  482. .I cost
  483. of a real-time process describes the maximum CPU time the process may use per period.
  484. .PP
  485. A real-time process can give up the CPU before its deadline is reached
  486. or its allocation is exhausted.
  487. It does this by calling
  488. .IR sleep (0).
  489. If
  490. .I yieldonblock
  491. is specified, it also does it by executing any blocking system call.
  492. .I Yieldonblock
  493. is assumed for
  494. .I sporadic
  495. processes.
  496. .PP
  497. Of the released processes,
  498. the one with the earliest deadline has the highest priority.
  499. Care should be taken using spin locks (see
  500. .IR lock (2))
  501. because a real-time process spinning on a lock will not give up the processor until
  502. its CPU allocation is exhausted; this is unlikely to be the desired behavior.
  503. .PP
  504. When a real-time process reaches its deadline or exhausts its CPU allocation, it remains
  505. schedulable, but at a very low priority.
  506. .PP
  507. The priority is interpreted by Plan 9's multilevel process scheduler.
  508. Priorities run from 0 to 19, with higher
  509. numbers representing higher priorities.
  510. A process has a base priority and
  511. a running priority which is less than or equal to the base priority.
  512. As a process uses up more of its allocated time, its priority is lowered.
  513. Unless
  514. explicitly set, user processes have base priority 10, kernel processes
  515. 13.
  516. Children inherit the parent's base priority.
  517. .SH FILES
  518. .nf
  519. .B /sys/src/9/*/mem.h
  520. .B /sys/src/9/*/dat.h
  521. .B /sys/include/trace.h
  522. .fi
  523. .SH SEE ALSO
  524. .IR trace (1),
  525. .IR debugger (2),
  526. .IR mach (2),
  527. .IR cons (3)
  528. .SH SOURCE
  529. .B /sys/src/9/port/devproc.c