Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!mit-eddie!ll-xn!ames!oliveb!sun!gorodish!guy From: guy%gorodish@Sun.COM (Guy Harris) Newsgroups: comp.unix.wizards Subject: Re: Using argv to show process status Message-ID: <26253@sun.uucp> Date: Fri, 21-Aug-87 15:29:01 EDT Article-I.D.: sun.26253 Posted: Fri Aug 21 15:29:01 1987 Date-Received: Sun, 23-Aug-87 04:34:47 EDT References: <1217@mhres.mh.nl> <26252@sun.uucp> Sender: news@sun.uucp Lines: 22 Keywords: argv ps > In short, this trick is NOT portable; it may be a nice hack, but don't depend > on it working. In addition, as Doug Gwyn points out, if the string you're writing is longer than the original argument, you will start scribbling on top of other strings, such as other arguments or environment variables. You *might*, conceivably, be able to save the arguments away before you smash them; however, it's not so easy to save the environment variables, because some routine you don't even know about may want to query one of them! You might be able to save them all, zero out your environment, and reconstruct it with "putenv" on a system that has "putenv"; however, it sounds like too much trouble. If you want to do this sort of thing, make VERY SURE you always overwrite the zeroth argument with exactly as many characters as it originally had, truncating or padding with NUL characters as needed. If the truncation is a problem, too bad. Remember, this trick depends on a *quirk of the implementation*; vendors are under no obligation whatsoever to provide implementations with this quirk. Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com