]> git.lizzy.rs Git - plan9front.git/blob - sys/man/3/proc
remove realemu manpage from src dir
[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, except its stack,
136 in units of 1024 bytes
137 .IP \-
138 the base and current scheduling priority, each 11 character numbers
139 .PP
140 The read-only
141 .B args
142 file contains the arguments of the program when it was created by
143 .IR exec (2).
144 If the program was not created by
145 .BR exec ,
146 such as by
147 .IR fork (2),
148 its
149 .B args
150 file will be empty.
151 The format of the file is a list of quoted strings suitable for
152 .BR tokenize ;
153 see
154 .IR getfields (2).
155 .PP
156 The
157 .B text
158 file is a pseudonym for the file
159 from which the process was executed;
160 its main use is to recover the symbol table of the process.
161 .PP
162 The
163 .B wait
164 file may be read to recover
165 records from the exiting children of the process in the format of
166 .B await
167 (see
168 .IR wait (2)).
169 If the process has no extant children, living or exited,
170 a read of
171 .B wait
172 will block.
173 It is an error for a process to attempt to read its own
174 .B wait
175 file when it has no children.
176 When a process's
177 .B wait
178 file is being read,
179 the process will draw an error
180 if it attempts an
181 .B await
182 system call; similarly, if a process is in an
183 .B await
184 system call, its
185 .B wait
186 file cannot be read by any process.
187 .PP
188 The read-only
189 .B profile
190 file contains the instruction frequency count information used for multiprocess profiling; see
191 .B tprof
192 in
193 .IR prof (1).
194 The information is gleaned by sampling the program's user-level program counter
195 at interrupt time.
196 .PP
197 Strings written to the
198 .B note
199 file will be posted as a note to the process
200 (see
201 .IR notify (2)).
202 The note should be less than
203 .B ERRLEN-1
204 characters long;
205 the last character is reserved for a terminating NUL character.
206 A read of at least
207 .B ERRLEN
208 characters will retrieve the oldest note posted to the
209 process and prevent its delivery to the process.
210 The
211 .B notepg
212 file is similar, but the note will be delivered to all the
213 processes in the target process's
214 .I note group
215 (see
216 .IR fork (2)).
217 However, if the process doing the write is in the group,
218 it will not receive the note.
219 The
220 .B notepg
221 file is write-only.
222 .PP
223 The textual
224 .B noteid
225 file may be read to recover an integer identifying the note group of the process
226 (see
227 .B RFNOTEG
228 in
229 .IR fork (2)).
230 The file may be written to cause the process to change to another note group,
231 provided the group exists and is owned by the same user.
232 .PP
233 The file
234 .B /proc/trace
235 can be opened once and read to see trace events from processes that have
236 had the string
237 .B trace
238 written to their
239 .B ctl
240 file.
241 Each event produces, in native machine format, the
242 .IR pid ,
243 a
244 .IR type ,
245 and a
246 .I "time stamp"
247 (see
248 .B /sys/include/trace.h
249 and
250 .BR /sys/src/cmd/trace.c ).
251 .
252 .SS Control messages
253 Textual messages written to the
254 .B ctl
255 file control the execution of the process.
256 Some require that the process is in a particular state
257 and return an error if it is not.
258 .TP 10n
259 .B stop
260 Suspend execution of the process, putting it in the
261 .B Stopped
262 state.
263 .TP 10n
264 .B start
265 Resume execution of a
266 .B Stopped
267 process.
268 .TP 10n
269 .B waitstop
270 Do not affect the process directly but, like all other messages ending with
271 .BR stop ,
272 block the process writing the
273 .B ctl
274 file until the target process is in the
275 .B Stopped
276 state or exits.
277 Also like other
278 .B stop
279 control messages,
280 if the target process would receive a note while the message is pending,
281 it is instead stopped and the debugging process is resumed.
282 .TP 10n
283 .B startstop
284 Allow a
285 .B Stopped
286 process to resume, and then do a
287 .B waitstop
288 action.
289 .TP 10n
290 .B hang
291 Set a bit in the process so that,
292 when it completes an
293 .IR exec (2)
294 system call, it will enter the
295 .B Stopped
296 state before returning to user mode.
297 This bit is inherited across
298 .IR fork (2)
299 and
300 .IR exec (2).
301 .TP 10n
302 .B "close\ \fIn
303 Close file descriptor
304 .I n
305 in the process.
306 .TP 10n
307 .B closefiles
308 Close all open file descriptors in the process.
309 .TP 10n
310 .B nohang
311 Clear the hang bit.
312 .TP 10n
313 .B noswap
314 Don't allow this process to be swapped out.  This should
315 be used carefully and sparingly or the system could run
316 out of memory.  It is meant for processes that can't be
317 swapped, like the ones implementing the swap device and for
318 processes containing sensitive data.
319 .TP 10n
320 .B kill
321 Kill the process the next time it crosses the user/kernel boundary.
322 .TP 10n
323 .B private
324 Make it impossible to read the process's user memory.
325 This property is inherited on fork, cleared on
326 .IR exec (2),
327 and is not otherwise resettable.
328 .TP 10n
329 .B "pri\ \fIn
330 Set the base priority for the process to the integer
331 .IR n .
332 .TP 10n
333 .B "wired\ \fIn
334 Wire the process to processor
335 .IR n .
336 .TP 10n
337 .B trace
338 Without an argument, toggle trace event generation for this process into
339 .B /proc/trace
340 (see below).
341 With a zero argument, tracing for the proc is turned off, with a non-zero numeric
342 argument, it is turned on.
343 .TP 10n
344 .B "period\ \fInu
345 Set the real-time scheduling period of the process to
346 .IR nu ,
347 where
348 .I n
349 is an optionally signed number containing an optional decimal point and
350 .I u
351 is one of
352 .BR s ,
353 .BR ms ,
354 .BR us ,
355 .BR µs ,
356 .BR ns ,
357 or
358 empty.  The time is interpreted, respectively, as
359 .IR seconds ,
360 .IR milliseconds ,
361 .IR microseconds ,
362 .IR microseconds ,
363 .IR nanoseconds ,
364 or, in the case of an absent units specifier, as
365 .IR nanoseconds .
366 If the time specifier is signed, it is interpreted as an increment or decrement
367 from a previously set value.  See also the
368 .B admit
369 command below.
370 .TP 10n
371 .B "deadline\ \fInu
372 Set the real-time deadline interval of the process to
373 .IR nu ,
374 where
375 .I n
376 and
377 .I u
378 are interpreted as for
379 .B period
380 above.
381 .TP 10n
382 .B "cost\ \fInu
383 Set the real-time cost (maximum CPU time per period) of the process to
384 .IR nu ,
385 where
386 .I n
387 and
388 .I u
389 are interpreted as for
390 .B period
391 above.
392 .TP 10n
393 .B "sporadic
394 Use sporadic scheduling for the real-time process.  The description of the
395 .B admit
396 command below contains further details.
397 .TP 10n
398 .B "yieldonblock
399 Make the real-time process yield on blocking I/O.
400   The description of the
401 .B admit
402 command below contains further details.
403 .TP 10n
404 .B "admit
405 Given real-time
406 .IR period ,
407 .I deadline
408 and
409 .I cost
410 are set (an unset
411 .I deadline
412 will set
413 .I deadline
414 to
415 .IR period ),
416 perform a schedulability test and start scheduling the process as a real-time
417 process if the test succeeds.  If the test fails, the
418 .B write
419 will fail with error set to the reason for failure.
420 .TP 10n
421 .B event
422 Add a user event to the
423 .B /proc/trace
424 file.
425 .PD
426 .
427 .SS Real-time scheduling
428 .I Real-time
429 processes are periodically
430 .IR released ,
431 giving them a higher priority than non-real-time processes until they either
432 give up the processor voluntarily, they exhaust their CPU allocation, or they reach their
433 .IR deadline .
434 The moment of release is dictated by the
435 .I period
436 and whether the process is
437 .I sporadic
438 or not.
439 Non-sporadic processes are called
440 .I periodic
441 and they are released precisely at intervals of their period (but periods can be skipped
442 if the process blocks on I/O).
443 Sporadic processes are released whenever they become
444 runnable (after being blocked by
445 .IR sleep ()
446 or I/O), but always at least an interval of
447 .I period
448 after the previous release.
449 .PP
450 The
451 .I deadline
452 of a real-time process specifies that the process must complete within the first
453 .I deadline
454 seconds of its
455 .IR period .
456 The dealine must be less than or equal to the period.
457 If it is not specified, it is set to the period.
458 .PP
459 The
460 .I cost
461 of a real-time process describes the maximum CPU time the process may use per period.
462 .PP
463 A real-time process can give up the CPU before its deadline is reached
464 or its allocation is exhausted.
465 It does this by calling
466 .IR sleep (0).
467 If
468 .I yieldonblock
469 is specified, it also does it by executing any blocking system call.
470 .I Yieldonblock
471 is assumed for
472 .I sporadic
473 processes.
474 .PP
475 Of the released processes,
476 the one with the earliest deadline has the highest priority.
477 Care should be taken using spin locks (see
478 .IR lock (2))
479 because a real-time process spinning on a lock will not give up the processor until
480 its CPU allocation is exhausted; this is unlikely to be the desired behavior.
481 .PP
482 When a real-time process reaches its deadline or exhausts its CPU allocation, it remains
483 schedulable, but at a very low priority.
484 .PP
485 The priority is interpreted by Plan 9's multilevel process scheduler.
486 Priorities run from 0 to 19, with higher
487 numbers representing higher priorities.
488 A process has a base priority and
489 a running priority which is less than or equal to the base priority.
490 As a process uses up more of its allocated time, its priority is lowered.
491 Unless
492 explicitly set, user processes have base priority 10, kernel processes
493 13.
494 Children inherit the parent's base priority.
495 .SH FILES
496 .nf
497 .B /sys/src/9/*/mem.h
498 .B /sys/src/9/*/dat.h
499 .B /sys/include/trace.h
500 .fi
501 .SH SEE ALSO
502 .IR trace (1),
503 .IR debugger (2),
504 .IR mach (2),
505 .IR cons (3)
506 .SH SOURCE
507 .B /sys/src/9/port/devproc.c