1 .\" Copyright (c) 2011 Sergey Kandaurov <pluknet@FreeBSD.org>
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .Nm procstat_open_core ,
32 .Nm procstat_open_kvm ,
33 .Nm procstat_open_sysctl ,
35 .Nm procstat_getargv ,
36 .Nm procstat_getauxv ,
37 .Nm procstat_getenvv ,
38 .Nm procstat_getfiles ,
39 .Nm procstat_getgroups ,
40 .Nm procstat_getkstack ,
41 .Nm procstat_getosrel ,
42 .Nm procstat_getpathname ,
43 .Nm procstat_getprocs ,
44 .Nm procstat_getumask ,
45 .Nm procstat_getvmmap ,
46 .Nm procstat_freeargv ,
47 .Nm procstat_freeauxv ,
48 .Nm procstat_freeenvv ,
49 .Nm procstat_freefiles ,
50 .Nm procstat_freegroups ,
51 .Nm procstat_freekstack ,
52 .Nm procstat_freeprocs ,
53 .Nm procstat_freevmmap ,
54 .Nm procstat_get_pipe_info ,
55 .Nm procstat_get_pts_info ,
56 .Nm procstat_get_shm_info ,
57 .Nm procstat_get_socket_info ,
58 .Nm procstat_get_vnode_info
59 .Nd library interface for file and process information retrieval
67 .Fn procstat_close "struct procstat *procstat"
70 .Fa "struct procstat *procstat"
74 .Fa "struct procstat *procstat"
75 .Fa "Elf_Auxinfo *auxv"
79 .Fa "struct procstat *procstat"
82 .Fo procstat_freefiles
83 .Fa "struct procstat *procstat"
84 .Fa "struct filestat_list *head"
87 .Fo procstat_freegroups
88 .Fa "struct procstat *procstat"
92 .Fo procstat_freekstack
93 .Fa "struct procstat *procstat"
94 .Fa "struct kinfo_kstack *kkstp"
97 .Fn procstat_freeprocs "struct procstat *procstat" "struct kinfo_proc *p"
99 .Fo procstat_freevmmap
100 .Fa "struct procstat *procstat"
101 .Fa "struct kinfo_vmentry *vmmap"
104 .Fo procstat_get_pipe_info
105 .Fa "struct procstat *procstat"
106 .Fa "struct filestat *fst"
107 .Fa "struct pipestat *pipe"
111 .Fo procstat_get_pts_info
112 .Fa "struct procstat *procstat"
113 .Fa "struct filestat *fst"
114 .Fa "struct ptsstat *pts"
118 .Fo procstat_get_shm_info
119 .Fa "struct procstat *procstat"
120 .Fa "struct filestat *fst"
121 .Fa "struct shmstat *shm"
125 .Fo procstat_get_socket_info
126 .Fa "struct procstat *procstat"
127 .Fa "struct filestat *fst"
128 .Fa "struct sockstat *sock"
132 .Fo procstat_get_vnode_info
133 .Fa "struct procstat *procstat"
134 .Fa "struct filestat *fst"
135 .Fa "struct vnstat *vn"
140 .Fa "struct procstat *procstat"
141 .Fa "const struct kinfo_proc *kp"
147 .Fa "struct procstat *procstat"
148 .Fa "struct kinfo_proc *kp"
149 .Fa "unsigned int *count"
153 .Fa "struct procstat *procstat"
154 .Fa "const struct kinfo_proc *kp"
158 .Ft "struct filestat_list *"
159 .Fo procstat_getfiles
160 .Fa "struct procstat *procstat"
161 .Fa "struct kinfo_proc *kp"
165 .Fo procstat_getgroups
166 .Fa "struct procstat *procstat"
167 .Fa "struct kinfo_proc *kp"
168 .Fa "unsigned int *count"
171 .Fo procstat_getosrel
172 .Fa "struct procstat *procstat"
173 .Fa "struct kinfo_proc *kp"
176 .Ft "struct kinfo_kstack *"
177 .Fo procstat_getkstack
178 .Fa "struct procstat *procstat"
179 .Fa "struct kinfo_proc *kp"
180 .Fa "unsigned int *count"
182 .Ft "struct kinfo_proc *"
183 .Fo procstat_getprocs
184 .Fa "struct procstat *procstat"
187 .Fa "unsigned int *count"
190 .Fo procstat_getpathname
191 .Fa "struct procstat *procstat"
192 .Fa "struct kinfo_proc *kp"
197 .Fo procstat_getrlimit
198 .Fa "struct procstat *procstat"
199 .Fa "struct kinfo_proc *kp"
201 .Fa "struct rlimit* rlimit"
204 .Fo procstat_getumask
205 .Fa "struct procstat *procstat"
206 .Fa "struct kinfo_proc *kp"
207 .Fa "unsigned short *maskp"
209 .Ft "struct kinfo_vmentry *"
210 .Fo procstat_getvmmap
211 .Fa "struct procstat *procstat"
212 .Fa "struct kinfo_proc *kp"
213 .Fa "unsigned int *count"
215 .Ft "struct procstat *"
216 .Fn procstat_open_core "const char *filename"
217 .Ft "struct procstat *"
218 .Fn procstat_open_kvm "const char *nlistf" "const char *memf"
219 .Ft "struct procstat *"
220 .Fn procstat_open_sysctl void
224 library contains the API for runtime file and process information
225 retrieval from the running kernel via the
227 library backend, and for post-mortem analysis via the
229 library backend, or from the process
231 file, searching for statistics in special
236 .Fn procstat_open_kvm
238 .Fn procstat_open_sysctl
243 library routines, respectively, to access kernel state information
244 used to retrieve processes and files states.
246 .Fn procstat_open_core
249 routines to access statistics stored as a set of notes in a process
251 file, written by the kernel at the moment of the process abnormal termination.
254 argument is the process core file name.
257 argument is the executable image of the kernel being examined.
260 the currently running kernel is assumed.
263 argument is the kernel memory device file.
272 The functions dynamically allocate and return a
274 structure pointer used in the rest of the
276 library routines until the corresponding
278 call that cleans up the resources allocated by the
283 .Fn procstat_getprocs
284 function gets a pointer to the
286 structure from one of the
288 functions and returns a dynamically allocated (sub-)set of active processes
289 in the kernel filled in to array of
296 arguments constitute a filtering predicate as described in the
299 The number of processes found is returned in the reference parameter
301 The caller is responsible to free the allocated memory with a subsequent
302 .Fn procstat_freeprocs
307 function gets a pointer to the
309 structure from one of the
311 functions, a pointer to
313 structure from the array obtained from the
315 function, and returns a null-terminated argument vector that corresponds to
316 the command line arguments passed to the process.
319 argument indicates the maximum number of characters, including null bytes,
320 to use in building the strings.
321 If this amount is exceeded, the string causing the overflow is truncated and
322 the partial result is returned.
323 This is handy for programs that print only a one line summary of a
324 command and should not copy out large amounts of text only to ignore it.
327 is zero, no limit is imposed and all argument strings are returned.
328 The values of the returned argument vector refer the strings stored
332 A subsequent call of the function with the same
334 argument will reuse the buffer.
335 To free the allocated memory
336 .Fn procstat_freeargv
337 function call can be used, or it will be released on
342 function is similar to
344 but returns the vector of environment strings.
345 The caller may free the allocated memory with a subsequent
351 function gets a pointer to the
353 structure, a pointer to
355 structure, and returns the auxiliary vector as a dynamically allocated array of
358 The caller is responsible to free the allocated memory with a subsequent
359 .Fn procstat_freeauxv
363 .Fn procstat_getfiles
364 function gets a pointer to the
366 structure initialized with one of the
368 functions, a pointer to
370 structure from the array obtained from the
372 function, and returns a dynamically allocated linked list of filled in
374 structures using the STAILQ macros defined in
376 The caller is responsible to free the allocated memory with a subsequent
377 .Fn procstat_freefiles
381 .Fn procstat_getgroups
382 function gets a pointer to the
384 structure, a pointer to
386 structure, and returns the process groups as a dynamically allocated array of
389 The caller is responsible to free the allocated memory with a subsequent
390 .Fn procstat_freegroups
394 .Fn procstat_getkstack
395 function gets a pointer to the
397 structure initialized with one of the
399 functions, a pointer to
401 structure, and returns kernel stacks of the process as a dynamically allocated
405 The caller is responsible to free the allocated memory with a subsequent
406 .Fn procstat_freekstack
410 .Fn procstat_getosrel
411 function gets a pointer to the
413 structure, a pointer to
415 structure, and returns osrel date in the 3rd reference parameter.
418 .Fn procstat_getpathname
419 function gets a pointer to the
421 structure, a pointer to
423 structure, and copies the path of the process executable to
430 .Fn procstat_getrlimit
431 function gets a pointer to the
433 structure, a pointer to
435 structure, resource index
437 and returns the actual resource limit in the 4th reference parameter.
440 .Fn procstat_getumask
441 function gets a pointer to the
443 structure, a pointer to
445 structure, and returns the process umask in the 3rd reference parameter.
448 .Fn procstat_getvmmap
449 function gets a pointer to the
451 structure initialized with one of the
453 functions, a pointer to
455 structure, and returns VM layout of the process as a dynamically allocated
459 The caller is responsible to free the allocated memory with a subsequent
460 .Fn procstat_freevmmap
464 .Fn procstat_get_pipe_info ,
465 .Fn procstat_get_pts_info ,
466 .Fn procstat_get_shm_info ,
467 .Fn procstat_get_socket_info
469 .Fn procstat_get_vnode_info
470 functions are used to retrieve information about pipes, pseudo-terminals,
471 shared memory objects,
472 sockets, and vnodes, respectively.
473 Each of them have a similar interface API.
476 argument is a pointer obtained from one of
481 argument is an element of STAILQ linked list as obtained from the
482 .Fn procstat_getfiles
488 field that specifies a file type and a corresponding function to be
490 .Nm procstat_get_*_info
492 The actual object is returned in the 3rd reference parameter.
495 argument indicates an actual error message in case of failure.
497 .Bl -tag -width 20n -compact -offset indent
498 .It Li PS_FST_TYPE_FIFO
499 .Nm procstat_get_vnode_info
500 .It Li PS_FST_TYPE_VNODE
501 .Nm procstat_get_vnode_info
502 .It Li PS_FST_TYPE_SOCKET
503 .Nm procstat_get_socket_info
504 .It Li PS_FST_TYPE_PIPE
505 .Nm procstat_get_pipe_info
506 .It Li PS_FST_TYPE_PTS
507 .Nm procstat_get_pts_info
508 .It Li PS_FST_TYPE_SHM
509 .Nm procstat_get_shm_info
533 library was written by
534 .An Stanislav Sedov Aq stas@FreeBSD.org .
536 This manual page was written by
537 .An Sergey Kandaurov Aq pluknet@FreeBSD.org .