1.\" Copyright (c) 1995 Peter Wemm <peter@freebsd.org> 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, is permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice immediately at the beginning of the file, without modification, 9.\" this list of conditions, and the following disclaimer. 10.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" notice, this list of conditions and the following disclaimer in the 12.\" documentation and/or other materials provided with the distribution. 13.\" 3. This work was done expressly for inclusion into FreeBSD. Other use 14.\" is permitted provided this notation is included. 15.\" 4. Absolutely no warranty of function or purpose is made by the author 16.\" Peter Wemm. 17.\" 5. Modifications may be freely made to this file providing the above 18.\" conditions are met. 19.\" 20.\" $FreeBSD$ 21.\" 22.\" The following requests are required for all man pages. 23.Dd December 16, 1995 24.Os 25.Dt SETPROCTITLE 3 26.Sh NAME 27.Nm setproctitle 28.Nd set process title 29.Sh SYNOPSIS 30.In sys/types.h 31.In unistd.h 32.Ft void 33.Fn setproctitle "const char *fmt" "..." 34.Sh DESCRIPTION 35The 36.Fn setproctitle 37library routine sets the process title that appears on the 38.Xr ps 1 39command. 40.Pp 41The title is set from the executable's name, followed by the 42result of a 43.Xr printf 3 44style expansion of the arguments as specified by the 45.Va fmt 46argument. 47If the 48.Va fmt 49argument begins with a 50.Dq - 51character, the executable's name is skipped. 52.Pp 53If 54.Va fmt 55is NULL, the process title is restored. 56.Sh EXAMPLES 57To set the title on a daemon to indicate its activity: 58.Bd -literal -offset indent 59setproctitle("talking to %s", inet_ntoa(addr)); 60.Ed 61.Sh SEE ALSO 62.Xr ps 1 , 63.Xr w 1 , 64.Xr kvm 3 , 65.Xr kvm_getargv 3 , 66.Xr printf 3 67.Sh STANDARDS 68The 69.Fn setproctitle 70function 71is implicitly non-standard. Other methods of causing the 72.Xr ps 1 73command line to change, including copying over the argv[0] string are 74also implicitly non-portable. It is preferable to use an operating system 75supplied 76.Fn setproctitle 77if present. 78.Pp 79Unfortunately, it is possible that there are other calling conventions 80to other versions of 81.Fn setproctitle , 82although none have been found by the author as yet. This is believed to be 83the predominant convention. 84.Pp 85It is thought that the implementation is compatible with other systems, 86including 87.Nx 88and 89.Bsx . 90.Sh HISTORY 91The 92.Fn setproctitle 93function 94first appeared in 95.Fx 2.2 . 96Other operating systems have 97similar functions. 98.Sh AUTHORS 99.An -nosplit 100.An Peter Wemm Aq peter@FreeBSD.org 101stole the idea from the 102.Sy "Sendmail 8.7.3" 103source code by 104.An Eric Allman Aq eric@sendmail.org . 105.Sh BUGS 106Never pass a string with user-supplied data as a format without using 107.Ql %s . 108An attacker can put format specifiers in the string to mangle your stack, 109leading to a possible security hole. 110This holds true even if the string was built using a function like 111.Fn snprintf , 112as the resulting string may still contain user-supplied conversion specifiers 113for later interpolation by 114.Fn setproctitle . 115.Pp 116Always use the proper secure idiom: 117.Pp 118.Dl setproctitle("%s", string); 119