1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
.TH PROC 4
.CT 2 proc_man
.SH NAME
proc \- process file system
.SH SYNOPSIS
.B #include <sys/proc.h>
.br
.B #include <sys/pioctl.h>
.SH DESCRIPTION
.I Proc
is a file-system mount point that provides access to the image of each
running process in the system.
The name of each entry in the
.F /proc
directory is a five-digit decimal number corresponding to the process
id.
The owner of each file is the userid of the process;
the group is \-1.
If the process's text file is readable, the owner is granted
read-write permission and the group is granted read permission.
The size of a file is
the total virtual memory size of the process.
The security label is shared with the process, unless the
process has had capability
.B T_NOCHK
(see
.IR getplab (2))
since last
.IR exec (2),
in which case the lattice value of the label is lattice
top and the privilege fields contain some past value of the
process' privilege fields.
.PP
The standard system-call interface is used to access
.I proc.
.I Open
and
.IR close (2)
behave as usual.
The object process is unaffected, except that setuid bits
will be ignored if it does an
.IR exec (2).
(Setuid bits are also ignored if the
.IR exec "ing"
process has traced signals, or stops on
.IR exec ;
see the description of
.B PIOCSMASK
and
.B PIOCSEXEC
below.)
Data may be transferred
from or to any locations in the object's address space through
.I lseek,
.I read,
and
.IR write (2).
The
.I text segment
begins at virtual address 0; the
.I data segment
starts above the text.
The
.I user area
extends downward below virtual address 0x80000000, and is
.B UPAGES*NBPG
bytes long; the
.I stack segment
grows downward below the user area.
Between the end of the data and
the beginning of the stack lies no-man's land.
The text, data, and stack sizes
may be determined from the process's
.L proc
structure (see below).
There are two differences from reading and writing ordinary files:
(1) no I/O transfer may span a segment boundary;
(2) the user area is writable only in the locations of saved user registers.
.PP
Several process control actions are available through an
.IR ioctl (2)
of the form
.IP
.L
union { struct proc p; long i; } buffer;
.br
.L retval = ioctl(fildes, code, &buffer);
.LP
The possible
.I codes
are as follows:
.TF PIOCSMASK
.TP
.B PIOCGETPR
copies the object's proc structure from the kernel process table
into
.BR buffer.p .
Since this information resides in system space, it is not accessible
via a normal read.
.PD
.TP
.B PIOCSTOP
sends the signal
.B SIGSTOP
to the object, and waits for it to
enter the stopped state.
.TP
.B PIOCWSTOP
simply waits for the object to stop.
.TP
.B PIOCRUN
makes the object runnable again after a stop.
.TP
.B PIOCSMASK
defines (via the bit mask
.BR buffer.i )
a set of signals to be traced;
i.e., the arrival of such a signal will cause the object to stop.
(The signal numbered
.I n
is specified by the bit
.BI "1<<(" n "-1)\fR.)"
A mask of zeroes turns off the trace.
The traced state and mask bits are inherited by the child of a
.IR fork (2).
When the object is closed, the mask bits are lost, but
the traced state is retained for side effects.
.TP
.B PIOCSEXEC
causes the object to stop after
.IR exec "ing."
This condition is inherited by children and is retained when the
object is closed.
.TP
.B PIOCREXEC
reverses the effect of
.BR PIOCSEXEC .
.TP
.B PIOCCSIG
clears the object's currently pending signal (if any).
.TP
.B PIOCKILL
sends a signal to the process.
.TP
.B PIOCOPENT
provides, in
.BR retval ,
a read-only file descriptor
for the object process's text file.
This allows a debugger to find the
symbol table without having to know any path names.
.TP
.B PIOCNICE
increments the object's
.IR nice (2)
priority by the amount
.BR buffer.i .
Only the super user may better a process's priority in this way, but any
user may make the priority worse.
.PP
All system calls are interruptible by signals, so that, for example,
an
.IR alarm (2)
may be set to avoid waiting forever for a process that may never stop.
Any system call is guaranteed to be atomic with respect to the object,
but, as with ordinary files, there is nothing to prevent more than one
process from trying to control the same object.
.PP
The following header files are useful in analyzing
.I proc
files:
.PP
.TF <sys/param.h>
.TP
.B <signal.h>
list of signal numbers
.TP
.B <sys/param.h>
size parameters
.TP
.B <sys/types.h>
special system types
.TP
.B <sys/user.h>
user structure
.TP
.B <sys/proc.h>
proc structure
.TP
.B <sys/reg.h>
locations of saved user registers
.TP
.B <sys/pioctl.h>
ioctl codes
.PD
.SH FILES
.F /proc/*
.SH SEE ALSO
.IR ps (1),
.IR hang (1),
.IR fmount (2),
.IR signal (2),
.IR mount (8),
.IR pi (9.1)
.SH DIAGNOSTICS
This is a list of errors which can occur in addition to the
errors normally associated with the file system; see
.IR intro (2):
.TF ENOENT
.TP
.B ENOENT
is returned if the object process has exited after being opened.
.TP
.B EIO
is returned if I/O is attempted at an illegal address in the object.
.TP
.B EBUSY
is returned if the object is in the midst of changing virtual memory
attributes, or has pages locked for physical I/O.
.TP
.B ENOSPC
is returned if a write is attempted on a shared text segment, but there
is no room on the swap space to make a copy.
.TP
.B EPERM
is returned if someone other than the super user attempts to better
a process's priority by issuing a
.BR PIOCNICE .
.SH BUGS
A process must be swapped in for reading and writing (but not
.IR ioctl );
this consumes minimal system resources, but may involve a noticeable
delay.
.br
The spectrum of states which result in the
.B EBUSY
error is too conservative.
.br
A process loaded from a text file with magic number 0407 does not have as
a read-only text segment; in this (presumably rare) case
.B PIOCOPENT
does not work, and the process is accessible even if the
text file is read-only.
|