setproctitle(3bsd)

πŸ“¦
version 0.12.2 Β· 3 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian trixie, epel 10, epel 9, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– setproctitle β€” set process title πŸ’–

okay bestie, welcome to setproctitle(3bsd) ✨ this one is a little libbsd baddie and she is here to make your process say what it's actually doing on ps. slay.


πŸ“š LIBRARY

utility functions from BSD systems, aka libbsd, and you link it with -lbsd 🫢


✨ SYNOPSIS ✨

#include <unistd.h>

(peep libbsd(7) for the whole include-usage situation, iykyk πŸ‘€)

void
setproctitle_init(int argc, char *argv[], char *envp[]);

void
setproctitle(const char *fmt, ...);

🌸 DESCRIPTION 🌸

so. the setproctitle() library routine sets the process title β€” the little name that shows up when you run ps(1) 😌 like, the thing everyone sees in top. main character energy, fr fr.

now, setproctitle_init() β€” she only needs to be called if the automatic constructor support hasn't been linked in through the libbsd-ctor pkgconf file. and when you do call her, it has to be before any call to setproctitle(), and she wants the main() arguments. no cap πŸ’…

the title itself gets set from the executable's name, followed by the result of a printf(3) style expansion of the arguments as specified by the fmt argument. okay so here's the cute part: if fmt begins with a "-" character, the executable's name gets skipped entirely πŸ™ˆ

and if fmt is NULL? the process title is restored. back to factory settings, we love a reset πŸŽ€


πŸ“ EXAMPLES πŸ“

say you wanna set the title on a daemon so everyone knows what it's up to:

setproctitle("talking to %s", inet_ntoa(addr));

look at her. iconic. the daemon is talking to someone and now the whole system knows 😭✨


πŸ‘€ SEE ALSO πŸ‘€

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

go read those too bestie, they're all in the group chat 🫢


⭐ STANDARDS ⭐

the setproctitle() function is implicitly non-standard. no cap, there is no committee blessing here πŸ’€

other methods of making the ps(1) command line change β€” including just copying over the argv[0] string β€” are also implicitly non-portable. so if your OS ships its own setproctitle(), it is preferable to use that one instead. use the native one if you got one, periodt πŸ‘‘

and unfortunately 😭 it's possible that there are other calling conventions for other versions of setproctitle() out there, although the author hasn't found any of them as yet. this one is believed to be the predominant convention. ngl that's the vibe.

it is thought that the implementation is compatible with other systems, including NetBSD and BSD/OS. so like, she plays nice πŸ’œ


πŸ¦‹ HISTORY πŸ¦‹

the setproctitle() function first appeared in NetBSD 1.0 and FreeBSD 2.2 🌈 and other operating systems have similar functions, so she's got cousins everywhere.

the setproctitle_init() function, though? that one is a libbsd extension that is not present on the BSDs. so avoid using it in portable code, bestie. it's giving "convenient but not for traveling" πŸ™ˆ


πŸ’œ AUTHORS πŸ’œ

Peter Wemm <peter@FreeBSD.org> β€” and honestly? he stole the idea from the Sendmail 8.7.3 source code by Eric Allman <eric@sendmail.org>. king behavior, we respect the citation 😌✨


πŸ’€ BUGS πŸ’€

okay listen up because this is the serious part and I need you to actually pay attention.

never pass a string with user-supplied data as a format without using '%s'. 🚨

an attacker can put format specifiers in that string to mangle your stack, which can lead to a possible security hole. and this holds true even if the string was built using a function like snprintf(), because the resulting string may still contain user-supplied conversion specifiers that get interpolated later by setproctitle(). so like, no shortcuts, no vibes-based security 😭

always use the proper secure idiom:

setproctitle("%s", string);

that's it. that's the whole thing. do it. every time. fr fr πŸ™


and that's the page, bestie!! πŸŽ€ this one comes from the Debian crew, dated December 7, 2022, and it's filed under the local section as setproctitle(3bsd). go forth and title your processes responsibly πŸ’…πŸ«Άβœ¨

πŸ“¦ where this page comes from