Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!rutgers!labrea!decwrl!spar!hunt From: hunt@spar.SPAR.SLB.COM (Neil Hunt) Newsgroups: comp.lang.c Subject: Re: Accessing argc & argv from a functi Message-ID: <274@spar.SPAR.SLB.COM> Date: Thu, 6-Aug-87 13:42:49 EDT Article-I.D.: spar.274 Posted: Thu Aug 6 13:42:49 1987 Date-Received: Sat, 8-Aug-87 12:53:44 EDT References: <22@flmis06.ATT.COM> <28700019@ccvaxa> Reply-To: hunt@spar.UUCP (Neil Hunt) Organization: Schlumberger Palo Alto Research - CASLAB Lines: 22 I have thought of another (rather silly) way to obtain the arguments to a program without having access to main: :-) Set up a command which uses ps to obtain the long listing of all processes, egrep the line containing the current PID obtained from getpid, pipe it through the stream editor using a script to throw away the useless parts of the ps listing, leaving just the args, and stick the whole lot into a file: sprintf(str, "ps -uwww | egrep %d | sed -f com > /tmp/args", getpid()); Execute the command pipe using system: system(str); Now open and read the file, and obtain the original args (which will not change even if your program screws up its stack and scribbles over everything). This method while slow, might be interesting for printing a fatal error message with some attribution. Neil/.