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