---
name: "openproc"
section: "3"
platform: "linux"
package: "procps"
version: "2:3.3.17-5"
release: "Debian 11 (Bullseye)"
platforms: ["linux"]
url: "https://new.carta.tech/openproc"
---

# openproc(3)

initialize process information from /proc/

## NAME

openproc, closeproc  - initialize process information from /proc/

## SYNOPSIS

**#include \<proc/readproc.h\>**

**PROCTAB\* openproc (int** *flags***, ... );**\
 **void closeproc (PROCTAB\*** *PT***);**

## SYNOPSIS

The **openproc** function initializes a PROCTAB structure which can be used by iterated readproc calls to get information on current processes. Depending on *flags*, openproc may need a second argument or a second and third argument (see below).

**closeproc** closes all files opened by **openproc** and deallocates the memory allocated by **openproc.**

The PROCTAB structure is defined in *\<proc/readproc.h\>*

## RETURN VALUE

**openproc** returns a pointer to a PROCTAB structure, or NULL if an error occurs. This usually means that */proc* cannot be read by the process.

## FLAGS

The behaviour of **openproc** is controlled by the following set of flags, which may be ORed together. There are three different kinds of flags. The first group of flags determines which information gets read from /proc/#pid for each process. The second group of flags (of which only one can be enacted for a opendir call) restricts which processes information is read for by providing a list of criteria. The third group of flags restricts this as well, but doesn't need arguments. These may be used together again.

- **PROC\_FILLMEM**

  read information from */proc/#pid/statm*

- **PROC\_FILLCOM**

  allocate *cmdline* part of *proc\_t* and read information from */proc/#pid/cmdline*

- **PROC\_FILLENV**

  allocate *environ* part of *proc\_t* and read information from */proc/#pid/environ*

- **PROC\_FILLUSR**

  resolve user ids to names via */etc/passwd*

- **PROC\_FILLGRP**

  resolve group ids to names via */etc/group*

- **PROC\_FILLSTATUS**

  read information from */proc/#pid/status*

- **PROC\_FILLSTAT**

  read information from */proc/#pid/stat*

- **PROC\_FILLARG**

  equivalent to PROC\_FILLCOM

- **PROC\_FILLCGROUP**

  alloc and fill in cgroup

- **PROC\_FILLSUPGRP**

  resolve supplementary group id -\> group name

- **PROC\_FILLOOM**

  fill in proc\_t oom\_score and oom\_adj

- **PROC\_FILLNS**

  fill in proc\_t namespace information

- **PROC\_FILLSYSTEMD**

  fill in proc\_t systemd information

- **PROC\_LOOSE\_TASKS**

  threat threads as if they were processes

- **PROC\_PID** (2nd argument **pid\_t\*** *pidlist*)

  lookup only processes whose pid is contained in *pidlist* (the list is terminated with 0)

- **PROC\_UID** (arguments **uid\_t\*** *uidlist***, int** *n*)

  lookup only processes whose user id is contained in *uidlist* (where *n* is the number of uids contained in the list)

- **PROC\_EDITCGRPCVT**

  edit cgroup as single vector

- **PROC\_EDITCMDLCVT**

  edit cmdline as single vector

- **PROC\_EDITENVRCVT**

  edit environ as single vector

## NOTE

Only one of the flags needing additional arguments (**PROC\_{PID,UID}**) may be used at a time.

## SEE ALSO

[**readproc**(3)](/readproc/3.md), [**readproctab**(3)](/readproctab/3.md), **/proc/**, **/usr/include/proc/readproc.h**,

## REPORTING BUGS

Please send bug reports to ⟨procps@freelists.org⟩
