xref: /illumos-gate/usr/src/man/man3proc/Lgrab.3proc (revision a7d7cafe)
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.\"
1243051d27SRobert Mustacchi.\" Copyright 2015 Joyent, Inc.
1343051d27SRobert Mustacchi.\"
14*a7d7cafeSRobert Mustacchi.Dd November 27, 2023
1543051d27SRobert Mustacchi.Dt LGRAB 3PROC
1643051d27SRobert Mustacchi.Os
1743051d27SRobert Mustacchi.Sh NAME
1843051d27SRobert Mustacchi.Nm Lgrab
1943051d27SRobert Mustacchi.Nd obtain a handle to control a thread
20*a7d7cafeSRobert Mustacchi.Sh LIBRARY
2143051d27SRobert Mustacchi.Lb libproc
22*a7d7cafeSRobert Mustacchi.Sh SYNOPSIS
2343051d27SRobert Mustacchi.In libproc.h
2443051d27SRobert Mustacchi.Ft "struct ps_lwphandle *"
2543051d27SRobert Mustacchi.Fo Lgrab
2643051d27SRobert Mustacchi.Fa "struct ps_prochandle *P"
2743051d27SRobert Mustacchi.Fa "lwpid_t lwpid"
2843051d27SRobert Mustacchi.Fa "int *perr"
2943051d27SRobert Mustacchi.Fc
3043051d27SRobert Mustacchi.Sh DESCRIPTION
3143051d27SRobert MustacchiThe
3243051d27SRobert Mustacchi.Fn Lgrab
3343051d27SRobert Mustacchifunction obtains a control handle to the thread identified by
3443051d27SRobert Mustacchi.Fa lwpid
3543051d27SRobert Mustacchiresiding under the process
3643051d27SRobert Mustacchi.Fa P .
3743051d27SRobert MustacchiThis handle is then passed as argument to other
3843051d27SRobert Mustacchi.Sy libproc
3972d3dbb9SYuri Pankovroutines.
4072d3dbb9SYuri PankovThe
4143051d27SRobert Mustacchi.Fa lwpid
4243051d27SRobert Mustacchican be obtained from the
4343051d27SRobert Mustacchi.Sy pr_lwpid
4443051d27SRobert Mustacchimember of the
4543051d27SRobert Mustacchi.Sy lwpstatus_t
4643051d27SRobert Mustacchistructure.
4743051d27SRobert Mustacchi.Pp
4843051d27SRobert MustacchiThe
4943051d27SRobert Mustacchi.Fa perr
5043051d27SRobert Mustacchiargument must point to a valid pointer that will be used to store an
5143051d27SRobert Mustacchierror code in the event that
5243051d27SRobert Mustacchi.Fn Lgrab
5372d3dbb9SYuri Pankovis unable to successfully obtain a handle to the process.
5472d3dbb9SYuri PankovThe possible errors are defined below in the
5543051d27SRobert Mustacchi.Sx ERRORS
5672d3dbb9SYuri Pankovsection.
5772d3dbb9SYuri PankovThe code may be transformed into a human readable string through the use of
5843051d27SRobert Mustacchi.Xr Lgrab_error 3PROC .
5943051d27SRobert Mustacchi.Pp
6043051d27SRobert MustacchiThe handle to the thread is valid until the
6143051d27SRobert Mustacchi.Xr Lfree 3PROC
6272d3dbb9SYuri Pankovfunction is called, which also releases associated resources from the handle.
6372d3dbb9SYuri PankovOnly a single handle to a specific thread may exist at any time.
6472d3dbb9SYuri PankovIf the handle already exists and another caller attempts to grab
6572d3dbb9SYuri Pankovthat thread, it will result in an error.
6672d3dbb9SYuri PankovThe caller must call
6743051d27SRobert Mustacchi.Fn Lfree
6843051d27SRobert Mustacchibefore releasing the handle associated with
6943051d27SRobert Mustacchi.Fa P .
7043051d27SRobert Mustacchi.Pp
7143051d27SRobert MustacchiUnlike grabbing a process, grabbing a thread does not change the current
7272d3dbb9SYuri Pankovstate of the thread.
7372d3dbb9SYuri PankovIf it is running, it will remain running.
7472d3dbb9SYuri PankovIf it is stopped, it will remain stopped.
7543051d27SRobert Mustacchi.Sh RETURN VALUES
7643051d27SRobert MustacchiUpon successful completion, the
7743051d27SRobert Mustacchi.Fn Lgrab
7872d3dbb9SYuri Pankovfunction returns a pointer to the control handle for the specified thread.
7972d3dbb9SYuri PankovOtherwise, the
8043051d27SRobert Mustacchi.Dv NULL
8143051d27SRobert Mustacchipointer is returned and
8243051d27SRobert Mustacchi.Fa perr
8343051d27SRobert Mustacchiis set to indicate the error.
8443051d27SRobert Mustacchi.Sh ERRORS
8543051d27SRobert MustacchiThe
8643051d27SRobert Mustacchi.Fn Lgrab
8743051d27SRobert Mustacchifunction will fail if:
8843051d27SRobert Mustacchi.Bl -tag -width Er
8943051d27SRobert Mustacchi.It Er G_BUSY
9043051d27SRobert MustacchiAnother handle already exists for the thread identified by
9143051d27SRobert Mustacchi.Fa lwpid .
9243051d27SRobert MustacchiThe handle need not exist in the current process and may exist in
9343051d27SRobert Mustacchianother process.
9443051d27SRobert Mustacchi.It Er G_NOPROC
9543051d27SRobert MustacchiThe thread identified by
9643051d27SRobert Mustacchi.Fa lwpid
9743051d27SRobert Mustacchidoes not exist or has already become a zombie.
9843051d27SRobert Mustacchi.It Er G_STRANGE
9972d3dbb9SYuri PankovAn unanticipated system error occurred while trying to create the handle.
10072d3dbb9SYuri PankovWhen this occurs, then the value of
10143051d27SRobert Mustacchi.Sy errno
10272d3dbb9SYuri Pankovis meaningful.
10372d3dbb9SYuri PankovSee
10443051d27SRobert Mustacchi.Xr errno 3C
10543051d27SRobert Mustacchifor more information and
10643051d27SRobert Mustacchi.Xr Intro 2
10743051d27SRobert Mustacchifor the list of possible errors.
10843051d27SRobert Mustacchi.El
10943051d27SRobert Mustacchi.Sh INTERFACE STABILITY
11043051d27SRobert Mustacchi.Sy Uncommitted
11143051d27SRobert Mustacchi.Sh MT-LEVEL
11243051d27SRobert Mustacchi.Sy MT-Safe
11343051d27SRobert Mustacchi.Sh SEE ALSO
11443051d27SRobert Mustacchi.Xr errno 3C ,
11543051d27SRobert Mustacchi.Xr libproc 3LIB ,
11643051d27SRobert Mustacchi.Xr Lfree 3PROC ,
11743051d27SRobert Mustacchi.Xr Lgrab_error 3PROC ,
118bbf21555SRichard Lowe.Xr proc 5
119