getprogname(3bsd) 3bsd getprogname(3bsd)

# [NAME](#NAME)

`getprogname`, `setprogname` — get and set program name

# [LIBRARY](#LIBRARY)

library “libbsd”

# [SYNOPSIS](#SYNOPSIS)

`#include <stdlib.h>` (See [libbsd(7)](/man/os/libbsd/libbsd.7) for include usage.)  
`const char *`  
`getprogname`(`void`);

`void`  
`setprogname`(`const char *progname`);

# [DESCRIPTION](#DESCRIPTION)

The [`getprogname`](#getprogname)() returns a string with the current program name, excluding any directory component. The function will return `NULL` if it was unable to get the program name from any known source.

The [`setprogname`](#setprogname)() function sets the current program name, stripping any directory component prefix. The function will keep a reference to the passed string pointer, so it must not be freed or modified while these functions might be called.

The implementations on most BSDs will try to initialize the program name at program startup time, and `libbsd` will try to infer it from various known sources depending on the target system. But it is not a portable assumption that the program name will be set without calling [`setprogname`](#setprogname~2)(), so portable programs should always call it after starting up.

# [SEE ALSO](#SEE_ALSO)

[setproctitle(3bsd)](/man/os/libbsd/setproctitle.3bsd).

# [HISTORY](#HISTORY)

The `setprogname`() and `getprogname`() functions first appeared in NetBSD 1.6, FreeBSD 4.4, DragonFly 2.1 and OpenBSD 5.4.

August 3, 2022 Linux 4.19.0-gvisor

---

Document: setprogname(3bsd) from libbsd 0.12.2-r11 (Chainguard OS)
Source: https://gitlab.freedesktop.org/libbsd/libbsd
