xref: /illumos-gate/usr/src/man/man3proc/proc_fdwalk.3proc (revision e00bdde3c6d406f40f53f3025defadc22f7ec31a)
1.\"
2.\" This file and its contents are supplied under the terms of the
3.\" Common Development and Distribution License ("CDDL"), version 1.0.
4.\" You may only use this file in accordance with the terms of version
5.\" 1.0 of the CDDL.
6.\"
7.\" A full copy of the text of the CDDL should have accompanied this
8.\" source.  A copy of the CDDL is also available via the Internet at
9.\" http://www.illumos.org/license/CDDL.
10.\"
11.\"
12.\" Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
13.\"
14.Dd November 27, 2023
15.Dt PROC_FDWALK 3PROC
16.Os
17.Sh NAME
18.Nm proc_fdwalk
19.Nd walk the open file descriptors for a process
20.Sh LIBRARY
21.Lb libproc
22.Sh SYNOPSIS
23.In libproc.h
24.Ft int
25.Fo proc_fdwalk
26.Fa "pid_t pid"
27.Fa "proc_fdwalk_f *func"
28.Fa "void *arg"
29.Fc
30.Sh DESCRIPTION
31The
32.Fn proc_fdwalk
33function walks all file descriptors currently open in the process with ID
34.Fa pid
35and calls the callback function
36.Fa func
37once for each file descriptor with the user-specified
38.Fa arg .
39The definition of
40.Vt proc_fdwalk_f
41is available in
42.Xr libproc 3LIB .
43.Pp
44.Fa func
45will be called once for each file descriptor and will have its first
46argument filled in with the contents of the corresponding
47.Pa /proc
48.Sy fdinfo
49file for the file descriptor.
50.Pp
51The return value of the caller's
52.Fa func
53function determines whether or not iteration will continue.
54If
55.Fa func
56returns a non-zero value, then iteration will terminate and that
57return value will be returned to the caller.
58To distinguish between system errors and caller errors, it is recommended that
59the function only return positive integers in the event of an error.
60.Sh RETURN VALUES
61Upon successful completion, the
62.Fn proc_fdwalk
63function returns
64.Sy 0 .
65Otherwise,
66.Sy -1
67is returned and
68.Sy errno
69is updated to reflect the error that occurred.
70.Sh ERRORS
71In addition to the errors listed below, the
72.Fn proc_fdwalk
73function may fail for the same reasons as the
74.Xr opendir 3C ,
75.Xr readdir 3C ,
76and
77.Xr malloc 3C
78functions.
79.Sh INTERFACE STABILITY
80.Sy Uncommitted
81.Sh MT-LEVEL
82.Sy MT-Safe
83.Sh SEE ALSO
84.Xr malloc 3C ,
85.Xr opendir 3C ,
86.Xr readdir 3C ,
87.Xr libproc 3LIB ,
88.Xr proc 5
89