143051d27SRobert Mustacchi.\" 243051d27SRobert Mustacchi.\" This file and its contents are supplied under the terms of the 343051d27SRobert Mustacchi.\" Common Development and Distribution License ("CDDL"), version 1.0. 443051d27SRobert Mustacchi.\" You may only use this file in accordance with the terms of version 543051d27SRobert Mustacchi.\" 1.0 of the CDDL. 643051d27SRobert Mustacchi.\" 743051d27SRobert Mustacchi.\" A full copy of the text of the CDDL should have accompanied this 843051d27SRobert Mustacchi.\" source. A copy of the CDDL is also available via the Internet at 943051d27SRobert Mustacchi.\" http://www.illumos.org/license/CDDL. 1043051d27SRobert Mustacchi.\" 1143051d27SRobert Mustacchi.\" 12a63fed2aSJason King.\" Copyright 2019 Joyent, Inc. 1343051d27SRobert Mustacchi.\" 14*a7d7cafeSRobert Mustacchi.Dd November 27, 2023 1543051d27SRobert Mustacchi.Dt PROC_WALK 3PROC 1643051d27SRobert Mustacchi.Os 1743051d27SRobert Mustacchi.Sh NAME 1843051d27SRobert Mustacchi.Nm proc_walk 1943051d27SRobert Mustacchi.Nd walk all processes or threads in /proc 20*a7d7cafeSRobert Mustacchi.Sh LIBRARY 2143051d27SRobert Mustacchi.Lb libproc 22*a7d7cafeSRobert Mustacchi.Sh SYNOPSIS 2343051d27SRobert Mustacchi.In libproc.h 2443051d27SRobert Mustacchi.Ft int 2543051d27SRobert Mustacchi.Fo proc_walk 2643051d27SRobert Mustacchi.Fa "proc_walk_f *func" 2743051d27SRobert Mustacchi.Fa "void *arg" 2843051d27SRobert Mustacchi.Fa "int flag" 2943051d27SRobert Mustacchi.Fc 3043051d27SRobert Mustacchi.Sh DESCRIPTION 3143051d27SRobert MustacchiThe 3243051d27SRobert Mustacchi.Fn proc_walk 3343051d27SRobert Mustacchifunction walks all threads and processes in /proc and calls the callback 3443051d27SRobert Mustacchifunction 3543051d27SRobert Mustacchi.Fa func 3643051d27SRobert Mustacchionce for each one with the user specified 3743051d27SRobert Mustacchi.Fa arg . 3843051d27SRobert MustacchiThe definition of the 3943051d27SRobert Mustacchi.Sy proc_walk_f 4043051d27SRobert Mustacchiis available in 4143051d27SRobert Mustacchi.Xr libproc 3LIB . 4243051d27SRobert Mustacchi.Pp 4343051d27SRobert Mustacchi.Fa func 4443051d27SRobert Mustacchiwill be called once for each process and will always have its first 4543051d27SRobert Mustacchiargument filled in with the value of the 4643051d27SRobert Mustacchi.Sy psinfo 4743051d27SRobert Mustacchifile of the process. 4843051d27SRobert MustacchiThe value of 4943051d27SRobert Mustacchi.Fa flag 5043051d27SRobert Mustacchicontrols whether or not information about the threads in the process are 5143051d27SRobert Mustacchiincluded and how many times the callback function 5243051d27SRobert Mustacchi.Fa func 5372d3dbb9SYuri Pankovis called. 5472d3dbb9SYuri PankovThe following values may be passed in for 5543051d27SRobert Mustacchi.Fa flag : 5643051d27SRobert Mustacchi.Bl -tag -width Dv -offset indent 5743051d27SRobert Mustacchi.It Dv PR_WALK_PROC 5843051d27SRobert MustacchiIndicates that the walker is only concerned with the process. 5943051d27SRobert Mustacchi.Fa func 6072d3dbb9SYuri Pankovwill be called once for each process in the system. 6172d3dbb9SYuri PankovOnly the 6243051d27SRobert Mustacchi.Sy psinfo 6343051d27SRobert Mustacchiwill be read for the process and passed to 6443051d27SRobert Mustacchi.Fa func . 6543051d27SRobert MustacchiThe second argument, the one for the 6643051d27SRobert Mustacchi.Sy lwpsinfo_t , 6743051d27SRobert Mustacchiwill be passed as 6843051d27SRobert Mustacchi.Dv NULL . 6943051d27SRobert Mustacchi.It Dv PR_WALK_LWP 7043051d27SRobert MustacchiThe caller wants both process and thread information. 7143051d27SRobert Mustacchi.Fa func 7272d3dbb9SYuri Pankovwill be called once for each thread in the system. 7372d3dbb9SYuri PankovIn addition to the process 7443051d27SRobert Mustacchi.Sy psinfo 7543051d27SRobert Mustacchiinformation, the ps specific information for a given thread will be 7643051d27SRobert Mustacchiincluded in the 7743051d27SRobert Mustacchi.Fa lwpsinfo_t 7843051d27SRobert Mustacchiargument. 7943051d27SRobert Mustacchi.El 8043051d27SRobert Mustacchi.Pp 81a63fed2aSJason KingIn addition, the following values may be combined with one of the above 82a63fed2aSJason Kingvalues of 83a63fed2aSJason King.Fa flag 84a63fed2aSJason Kingwith a bitwise-inclusive-OR: 85a63fed2aSJason King.Bl -tag -width Dv -offset indent 86a63fed2aSJason King.It Dv PR_WALK_INCLUDE_SYS 87a63fed2aSJason KingInclude 88a63fed2aSJason King.Sy SYS 89a63fed2aSJason King.Pq system 90a63fed2aSJason Kingprocesses. 91a63fed2aSJason KingNormally 92a63fed2aSJason King.Sy SYS 93a63fed2aSJason Kingprocesses are skipped during the walk of the process tree. 94a63fed2aSJason King.El 95a63fed2aSJason King.Pp 9643051d27SRobert MustacchiThe return value of the caller's 9743051d27SRobert Mustacchi.Fa func 9872d3dbb9SYuri Pankovfunction determines whether or not iteration will continue. 9972d3dbb9SYuri PankovIf 10043051d27SRobert Mustacchi.Fa func 10143051d27SRobert Mustacchireturns a non-zero value, then iteration will terminate and that 10272d3dbb9SYuri Pankovreturn value will be returned to the caller. 10372d3dbb9SYuri PankovTo distinguish between system errors and caller errors, it is recommended that 10472d3dbb9SYuri Pankovthe function only return positive integers in the event of an error. 10543051d27SRobert Mustacchi.Sh RETURN VALUES 10643051d27SRobert MustacchiUpon successful completion, the 10743051d27SRobert Mustacchi.Fn proc_walk 10843051d27SRobert Mustacchifunction returns 10943051d27SRobert Mustacchi.Sy 0 . 11043051d27SRobert MustacchiOtherwise, 11143051d27SRobert Mustacchi.Sy -1 11243051d27SRobert Mustacchiis returned and 11343051d27SRobert Mustacchi.Sy errno 11443051d27SRobert Mustacchiis updated to reflect the error that occurred. 11543051d27SRobert Mustacchi.Sh ERRORS 11643051d27SRobert MustacchiIn addition to the errors listed below, the 11743051d27SRobert Mustacchi.Fn proc_walk 11843051d27SRobert Mustacchifunction may fail for the same reasons as the 11943051d27SRobert Mustacchi.Xr opendir 3C , 12043051d27SRobert Mustacchi.Xr readdir 3C , 12143051d27SRobert Mustacchiand 12243051d27SRobert Mustacchi.Xr malloc 3C 12343051d27SRobert Mustacchifunctions. 12443051d27SRobert Mustacchi.Bl -tag -width Er 12543051d27SRobert Mustacchi.It Er EINVAL 126a63fed2aSJason King.Fa flag 127a63fed2aSJason Kingis not one of 12843051d27SRobert Mustacchi.Dv PR_WALK_PROC 12943051d27SRobert Mustacchior 13043051d27SRobert Mustacchi.Dv PR_WALK_LWP . 13143051d27SRobert Mustacchi.El 13243051d27SRobert Mustacchi.Sh INTERFACE STABILITY 13343051d27SRobert Mustacchi.Sy Uncommitted 13443051d27SRobert Mustacchi.Sh MT-LEVEL 13543051d27SRobert Mustacchi.Sy MT-Safe 13643051d27SRobert Mustacchi.Sh SEE ALSO 13743051d27SRobert Mustacchi.Xr malloc 3C , 13843051d27SRobert Mustacchi.Xr opendir 3C , 13943051d27SRobert Mustacchi.Xr readdir 3C , 14043051d27SRobert Mustacchi.Xr libproc 3LIB , 141bbf21555SRichard Lowe.Xr proc 5 142