From owner-freebsd-hackers Fri Jan 19 07:18:03 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id HAA18750 for hackers-outgoing; Fri, 19 Jan 1996 07:18:03 -0800 (PST) Received: from px.f1.ru (root@px.f1.ru [194.87.86.19]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id HAA18682 for ; Fri, 19 Jan 1996 07:17:26 -0800 (PST) Received: (from am@localhost) by px.f1.ru (8.6.11/8.6.9) id SAA05118 for freebsd-hackers@freebsd.org; Fri, 19 Jan 1996 18:11:56 +0300 Message-Id: <199601191511.SAA05118@px.f1.ru> Subject: setproctitle() To: freebsd-hackers@freebsd.org Date: Fri, 19 Jan 1996 18:11:55 +0300 (MSK) From: "Andrew Maltsev" Organization: F1 communications Reply-To: am@f1.ru X-Mailer: ELM [version 2.4 PL24alpha5] MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: 8bit Sender: owner-hackers@freebsd.org Precedence: bulk Hi, All! Why we have no interface to change process name in FreeBSD? Like setproctitle() in BSD/OS and some other OS'es.. The following is my source, based on old source code from BSD/386 1.1 or 1.0.. I don't remember. I tested it a bit.. Somebody from core team - what about to add a module to libc.a? I'm not sure about man page - there is no BSD/OS near me to check man's presense and copyright notices.. /************************************************************ * setproctitle(const char *fmt, ...) - process name changer * Adopted for FreeBSD by Andrew Maltsev */ #include #include #include #include #include #include void setproctitle(const char *fmt, ...) { va_list ap; int n; char c = '\0'; char *buf = &c; struct ps_strings *psp = (struct ps_strings *)PS_STRINGS; va_start(ap, fmt); n = vsnprintf(buf, 1, fmt, ap); va_end(ap); if ((buf = malloc(++n)) == 0) return; va_start(ap, fmt); vsnprintf(buf, n, fmt, ap); va_end(ap); psp->ps_argvstr = buf; /* Not sure about this line - for what? But leaved as is to make it * compatible with BSD/OS */ psp->ps_nargvstr = 1; } #ifdef DEBUG main() { setproctitle("Wow, my pid is %d!",getpid()); system("ps"); } #endif -- am