1SETPROCTITLE(3bsd)                   LOCAL                  SETPROCTITLE(3bsd)
2

NAME

4     setproctitle — set process title
5

LIBRARY

7     Utility functions from BSD systems (libbsd, -lbsd)
8

SYNOPSIS

10     #include <sys/types.h>
11     #include <unistd.h>
12     (See libbsd(7) for include usage.)
13
14     void
15     setproctitle_init(int argc, char *argv[], char *envp[]);
16
17     void
18     setproctitle(const char *fmt, ...);
19

DESCRIPTION

21     The setproctitle() library routine sets the process title that appears on
22     the ps(1) command.
23
24     The setproctitle_init() library routine only needs to be called (before
25     any call to setproctitle() and with main() arguments), if the automatic
26     constructor support has not been linked in through the libbsd-ctor pkg-
27     config file.
28
29     The title is set from the executable's name, followed by the result of a
30     printf(3) style expansion of the arguments as specified by the fmt argu‐
31     ment.  If the fmt argument begins with a “-” character, the executable's
32     name is skipped.
33
34     If fmt is NULL, the process title is restored.
35

EXAMPLES

37     To set the title on a daemon to indicate its activity:
38
39           setproctitle("talking to %s", inet_ntoa(addr));
40

SEE ALSO

42     ps(1), w(1), kvm(3), kvm_getargv(3), printf(3)
43

STANDARDS

45     The setproctitle() function is implicitly non-standard.  Other methods of
46     causing the ps(1) command line to change, including copying over the
47     argv[0] string are also implicitly non-portable.  It is preferable to use
48     an operating system supplied setproctitle() if present.
49
50     Unfortunately, it is possible that there are other calling conventions to
51     other versions of setproctitle(), although none have been found by the
52     author as yet.  This is believed to be the predominant convention.
53
54     It is thought that the implementation is compatible with other systems,
55     including NetBSD and BSD/OS.
56

HISTORY

58     The setproctitle() function first appeared in FreeBSD 2.2.  Other operat‐
59     ing systems have similar functions.
60
61     The setproctitle_init() function is a libbsd extension not present on the
62     BSDs, avoid using it in portable code.
63

AUTHORS

65     Peter Wemm <peter@FreeBSD.org> stole the idea from the Sendmail 8.7.3
66     source code by Eric Allman <eric@sendmail.org>.
67

BUGS

69     Never pass a string with user-supplied data as a format without using
70     ‘%s’.  An attacker can put format specifiers in the string to mangle your
71     stack, leading to a possible security hole.  This holds true even if the
72     string was built using a function like snprintf(), as the resulting
73     string may still contain user-supplied conversion specifiers for later
74     interpolation by setproctitle().
75
76     Always use the proper secure idiom:
77
78           setproctitle("%s", string);
79
80BSD                            December 16, 1995                           BSD
Impressum