---
name: "pmdaGetOpt"
section: "3"
platform: "linux"
package: "pcp"
version: "7.2.2-2"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/pmdaGetOpt"
---

# pmdaGetOpt(3)

get options from arguments, parsing generic PMDA options

## NAME

**pmdaGetOpt**, **pmdaGetOptions** - get options from arguments, parsing generic PMDA options

## C SYNOPSIS

**#include \<pcp/pmapi.h\>**\
 **#include \<pcp/pmda.h\>**

**int pmdaGetOptions(int** *argc***,** **char \*const \****argv***,** **pmdaOptions \****opts***,** **pmdaInterface \****dispatch***);**\
 **int pmdaGetOpt(int** *argc***,** **char \*const \****argv***,** **const char \****optstring***,** **pmdaInterface \****dispatch***,** **int \****err***);**

**cc ... -lpcp\_pmda -lpcp**

## DESCRIPTION

These functions are wrappers for [**pmgetopt\_r**(3)](/pmgetopt_r/3.md). The behavior of each function is that certain options are assumed to have a predefined behavior which initializes several fields in the **pmdaInterface** structure. The **pmdaGetOptions** interface allows both short and long options to be given, whereas **pmdaGetOpt** allows for short form options only.

The options that both **pmdaGetOptions** and **pmdaGetOpt** will trap are:

- **-D***debugspec*

  Set the [**PMAPI**(3)](/PMAPI/3.md) debugging options to *debugspec*, as described in [**PCPIntro**(1)](/PCPIntro/1.md). Used for controlling levels of trace output while debugging.

- **-d***domain*

  Set the *domain* number of this agent.

- **-h***helpfile*

  Obtain the help text (see [**pmdaText**(3)](/pmdaText/3.md)) for the metrics from this file rather than from the path specified with [**pmdaDSO**(3)](/pmdaDSO/3.md) or [**pmdaDaemon**(3)](/pmdaDaemon/3.md).

- **-i***port*

  Expect PMCD to connect on inet *port* (number or name).

- **-6***port*

  Expect PMCD to connect on ipv6 *port* (number or name).

- **-l***logfile*

  Redirect diagnostics and trace output to *logfile*.

- **-p**

  Expect PMCD to supply stdin/stdout pipe.

- **-u***socket*

  Expect PMCD to connect on unix domain *socket*.

The **pmdaGetOptions** interface will also capture the following options, and store them within the *opts* parameter:

- **-U***username*

  Set the user account name under which the PMDA should execute.

Only one of **-i**, **-6**, **-p** and **-u** may be specified.  If none of these three options is given, a pipe (**-p**) is assumed.  When these options are encountered by **pmdaGetOpt**, the option is processed and the next option is examined.  Therefore, **pmdaGetOpt** will only return when an option other than those listed above is found, or the end of the list is reached.  The returned value will be the argument or EOF, respectively.

A PMDA can control which of these options the program will accept with either the *opts* or *optstring* argument.  To accept all the options, the PMDA should call **pmdaGetOptions** with the short\_options field of the *opts* structure set to the PMDA\_OPTIONS macro, or **pmdaGetOpt** with the option string "D:d:h:i:l:pu:". Any PMDA specific options should be added to these strings in the style of [**getopt**(3)](/getopt/3.md), and will be returned by both **pmdaGetOptions** and **pmdaGetOpt** if encountered.

When a command line option usage error is detected in the **pmdaGetOptions** interface, the error field of the *opts* structure will contain a non-zero error count.

**pmdaGetOpt** takes a pointer to an int, *err*, which is used as an error count.  This variable should be initialized to zero before **pmdaGetOpt** is first called, and tested when **pmdaGetOpt** returns EOF.

Neither **pmdaGetOptions** nor **pmdaGetOpt** modify their *argc* or *argv* parameters.

The global variables used by the system **getopt (3)** interface may also be used by the caller of **pmdaGetOpt** within the argument parsing loop.

On the other hand, the **pmdaGetOptions** interface does not utilize global variables at all (neither reading nor modifying them). Instead, these variables can be access via the *opts* fields of the same name.

## CAVEAT

The options **-D**, **-d**, **-i**, **-l**, **-p** and **-u** cannot be reused for other purposes by the PMDA, unless using the *override* method provided by the **pmdaGetOptions** interface, which operates in the same way as described for the [**pmGetOptions**(3)](/pmGetOptions/3.md) interface used by PMAPI client tools.

The PMDA must be using **PMDA\_INTERFACE\_2** or later, as specified in the call to [**pmdaDSO**(3)](/pmdaDSO/3.md) or [**pmdaDaemon**(3)](/pmdaDaemon/3.md).

## DIAGNOSTICS

Both **pmdaGetOptions** and **pmdaGetOpt** will display the same error messages as **getopt**.

## SEE ALSO

[**pmdbg**(1)](/pmdbg/1.md), [**getopt**(3)](/getopt/3.md), [**pmgetopt\_r**(3)](/pmgetopt_r/3.md), [**pmGetOptions**(3)](/pmGetOptions/3.md), [**PMAPI**(3)](/PMAPI/3.md), [**PMDA**(3)](/PMDA/3.md), [**pmdaDaemon**(3)](/pmdaDaemon/3.md), [**pmdaDSO**(3)](/pmdaDSO/3.md) and [**pmdaText**(3)](/pmdaText/3.md).
