[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]
Base Operating System and Extensions Technical Reference, Volume 1

getthrds Subroutine

Purpose

Gets kernel thread table entries.

Library

Standard C library (libc.a)

Syntax

#include <procinfo.h>
#include <sys/types.h>
int 
getthrds (ProcessIdentifier, ThreadBuffer, ThreadSize, IndexPointer, Count)
pid_t ProcessIdentifier;
struct thrdsinfo *ThreadBuffer;
or struct thrdsinfo64 *ThreadBuffer;
int ThreadSize;
tid_t *IndexPointer;
int Count;

Description

The getthrds subroutine returns information about kernel threads, including kernel thread table information defined by the thrdsinfo or thrdsinfo64 structure.

The getthrds subroutine retrieves up to Count kernel thread table entries, starting with the entry corresponding to the thread identifier indicated by IndexPointer, and places them in the array of thrdsinfo or thrdsinfo64 structures indicated by the ThreadBuffer parameter.

On return, the kernel thread identifier referenced by IndexPointer is updated to indicate the next kernel thread table entry to be retrieved. The getthrds subroutine returns the number of kernel thread table entries retrieved.

If the ProcessIdentifier parameter indicates a process identifier, only kernel threads belonging to that process are considered. If this parameter is set to -1, all kernel threads are considered.

The getthrds subroutine is normally called repeatedly in a loop, starting with a kernel thread identifier of zero, and looping until the return value is less than Count, indicating that there are no more entries to retrieve.

  1. Do not use information from the procsinfo structure (see the getprocs subroutine) to determine the value of the Count parameter; a process may create or destroy kernel threads in the interval between a call to getprocs and a subsequent call to getthrds.
  2. The kernel thread table may change while the getthrds subroutine is accessing it. Returned entries will always be consistent, but since kernel threads can be created or destroyed while the getthrds subroutine is running, there is no guarantee that retrieved entries will still exist, or that all existing kernel threads have been retrieved.

When used in 32-bit mode, limits larger than can be represented in 32 bits are truncated to RLIM_INFINITY. Large values are truncated to INT_MAX. Alternatively, the struct thrdsinfo64 and sizeof (struct thrdsinfo64) can be used by 32-bit getthrds to return full 64-bit thread information. Note that the thrdsinfo64 structure not only inceases certain thrdsinfo fields from 32 to 64 bits, but that it contains additional information not present in thrdsinfo. The struct thrdsinfo64 contains the same data as struct thrdsinfo when compiled in a 64-bit program.

Parameters

ProcessIdentifier Specifies the process identifier of the process whose kernel threads are to be retrieved. If this parameter is set to -1, all kernel threads in the kernel thread table are retrieved.
ThreadBuffer Specifies the starting address of an array of thrdsinfo or thrdsinfo64 structures which will be filled in with kernel thread table entries. If a value of NULL is passed for this parameter, the getthrds subroutine scans the kernel thread table and sets return values as normal, but no kernel thread table entries are retrieved.
ThreadSize Specifies the size of a single thrdsinfo or thrdsinfo64 structure.
IndexPointer Specifies the address of a kernel thread identifier which indicates the required kernel thread table entry (this does not have to correspond to an existing kernel thread). A kernel thread identifier of zero selects the first entry in the table. The kernel thread identifier is updated to indicate the next entry to be retrieved.
Count Specifies the number of kernel thread table entries requested.

Return Value

If successful, the getthrds subroutine returns the number of kernel thread table entries retrieved; if this is less than the number requested, the end of the kernel thread table has been reached. Otherwise, a value of -1 is returned, and the errno global variable is set to indicate the error.

Error Codes

The getthrds subroutine fails if the following are true:

EINVAL The ThreadSize is invalid, or the IndexPointer parameter does not point to a valid kernel thread identifier, or the Count parameter is not greater than zero.
ESRCH The process specified by the ProcessIdentifier parameter does not exist.
EFAULT The copy operation to one of the buffers failed.

Implementation Specifics

This subroutine is part of the Base Operating System (BOS) Runtime.

Related Information

The getpid, getpgrp, or getppid subroutines, the getprocs subroutine.

The ps command.


[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]