summaryrefslogtreecommitdiff
path: root/usr/src/man/man3proc/proc_walk.3proc
blob: 49f0489dc3435b2bfc2f0d77f929f9ac3fe13903 (plain)
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
.\"
.\" This file and its contents are supplied under the terms of the
.\" Common Development and Distribution License ("CDDL"), version 1.0.
.\" You may only use this file in accordance with the terms of version
.\" 1.0 of the CDDL.
.\"
.\" A full copy of the text of the CDDL should have accompanied this
.\" source.  A copy of the CDDL is also available via the Internet at
.\" http://www.illumos.org/license/CDDL.
.\"
.\"
.\" Copyright 2019 Joyent, Inc.
.\"
.Dd December  2, 2019
.Dt PROC_WALK 3PROC
.Os
.Sh NAME
.Nm proc_walk
.Nd walk all processes or threads in /proc
.Sh SYNOPSIS
.Lb libproc
.In libproc.h
.Ft int
.Fo proc_walk
.Fa "proc_walk_f *func"
.Fa "void *arg"
.Fa "int flag"
.Fc
.Sh DESCRIPTION
The
.Fn proc_walk
function walks all threads and processes in /proc and calls the callback
function
.Fa func
once for each one with the user specified
.Fa arg .
The definition of the
.Sy proc_walk_f
is available in
.Xr libproc 3LIB .
.Pp
.Fa func
will be called once for each process and will always have its first
argument filled in with the value of the
.Sy psinfo
file of the process.
The value of
.Fa flag
controls whether or not information about the threads in the process are
included and how many times the callback function
.Fa func
is called.
The following values may be passed in for
.Fa flag :
.Bl -tag -width Dv -offset indent
.It Dv PR_WALK_PROC
Indicates that the walker is only concerned with the process.
.Fa func
will be called once for each process in the system.
Only the
.Sy psinfo
will be read for the process and passed to
.Fa func .
The second argument, the one for the
.Sy lwpsinfo_t ,
will be passed as
.Dv NULL .
.It Dv PR_WALK_LWP
The caller wants both process and thread information.
.Fa func
will be called once for each thread in the system.
In addition to the process
.Sy psinfo
information, the ps specific information for a given thread will be
included in the
.Fa lwpsinfo_t
argument.
.El
.Pp
In addition, the following values may be combined with one of the above
values of
.Fa flag
with a bitwise-inclusive-OR:
.Bl -tag -width Dv -offset indent
.It Dv PR_WALK_INCLUDE_SYS
Include
.Sy SYS
.Pq system
processes.
Normally
.Sy SYS
processes are skipped during the walk of the process tree.
.El
.Pp
The return value of the caller's
.Fa func
function determines whether or not iteration will continue.
If
.Fa func
returns a non-zero value, then iteration will terminate and that
return value will be returned to the caller.
To distinguish between system errors and caller errors, it is recommended that
the function only return positive integers in the event of an error.
.Sh RETURN VALUES
Upon successful completion, the
.Fn proc_walk
function returns
.Sy 0 .
Otherwise,
.Sy -1
is returned and
.Sy errno
is updated to reflect the error that occurred.
.Sh ERRORS
In addition to the errors listed below, the
.Fn proc_walk
function may fail for the same reasons as the
.Xr opendir 3C ,
.Xr readdir 3C ,
and
.Xr malloc 3C
functions.
.Bl -tag -width Er
.It Er EINVAL
.Fa flag
is not one of
.Dv PR_WALK_PROC
or
.Dv PR_WALK_LWP .
.El
.Sh INTERFACE STABILITY
.Sy Uncommitted
.Sh MT-LEVEL
.Sy MT-Safe
.Sh SEE ALSO
.Xr malloc 3C ,
.Xr opendir 3C ,
.Xr readdir 3C ,
.Xr libproc 3LIB ,
.Xr proc 4