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