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