---
name: "explain_setpgrp_or_die"
section: "3"
platform: "linux"
package: "libexplain-dev"
version: "1.4.D001-16"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/explain_setpgrp_or_die"
---

# explain\_setpgrp\_or\_die(3)

set process group and report errors

## NAME

explain\_setpgrp\_or\_die - set process group and report errors

## SYNOPSIS

\#include \<libexplain/setpgrp.h\>

void explain\_setpgrp\_or\_die(pid\_t pid, pid\_t pgid);\
 int explain\_setpgrp\_on\_error(pid\_t pid, pid\_t pgid);

## DESCRIPTION

The **explain\_setpgrp\_or\_die** function is used to call the [*setpgrp*(2)](/setpgrp/2.md) system call. On failure an explanation will be printed to *stderr*, obtained from the [*explain\_setpgrp*(3)](/explain_setpgrp/3.md) function, and then the process terminates by calling `exit(EXIT_FAILURE)`.

The **explain\_setpgrp\_on\_error** function is used to call the [*setpgrp*(2)](/setpgrp/2.md) system call. On failure an explanation will be printed to *stderr*, obtained from the [*explain\_setpgrp*(3)](/explain_setpgrp/3.md) function, but still returns to the caller.

- *pid*

  The pid, exactly as to be passed to the [*setpgrp*(2)](/setpgrp/2.md) system call.

- *pgid*

  The pgid, exactly as to be passed to the [*setpgrp*(2)](/setpgrp/2.md) system call.

**Note:** the [*setpgrp*(2)](/setpgrp/2.md) function has two implementations. The System V version has no arguments, while the BSD version has two arguments.  For simplicity of implementation, the argument list seen here includes the *pid* and *pgid* arguments.

The System V `getpgid()` semantics can be obtained by calling `setpgrp(0, 0)` on systems with the BSD version, and this is the API for libexplain, even on systems that do not use the BSD API.

## RETURN VALUE

The **explain\_setpgrp\_or\_die** function only returns on success, see [*setpgrp*(2)](/setpgrp/2.md) for more information. On failure, prints an explanation and exits, it does not return.

The **explain\_setpgrp\_on\_error** function always returns the value return by the wrapped [*setpgrp*(2)](/setpgrp/2.md) system call.

## EXAMPLE

The **explain\_setpgrp\_or\_die** function is intended to be used in a fashion similar to the following example:

```
explain_setpgrp_or_die(pid, pgid);
```

## SEE ALSO

- [*setpgrp*(2)](/setpgrp/2.md)

  set process group

- [*explain\_setpgrp*(3)](/explain_setpgrp/3.md)

  explain [*setpgrp*(2)](/setpgrp/2.md) errors

- [*exit*(2)](/exit/2.md)

  terminate the calling process

## COPYRIGHT

libexplain version 1.4\
 Copyright (C) 2011 Peter Miller
