Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ukma!xanth!kremer From: kremer@cs.odu.edu (Lloyd Kremer) Newsgroups: comp.lang.c Subject: Re: modifying parent's environment, etc. Summary: A way to do it in SYSV Message-ID: <8634@xanth.cs.odu.edu> Date: 25 Apr 89 20:34:21 GMT References: <2158@pur-phy> <1494@vsedev.VSE.COM> Organization: Old Dominion University, Norfolk, Va. Lines: 46 In article <1494@vsedev.VSE.COM> logan@vsedev.VSE.COM (James Logan III) writes: >In article <2158@pur-phy> sho@newton.physics.purdue.edu.UUCP >(Sho Kuwamoto) writes: ># This thread got me to thinking. I wrote a quickie program which, ># for reasons I don't need to go into now, modified argv[i]. The ># strangest thing happened: if you run it in the background and look ># at it using ps, the line where it tells you what you typed in as ># your command line changes. I'm interested to know if this works ># on all versions of UNIX. Compile the following, run it in the ># background, and do a PS. Over here, we are running BSD 4.3. > >I tried it under System V Release 2. It doesn't work. Yes, in System V, writing to argv[] doesn't change ps's opinion of what the original args were. You must use some form of the exec() call to change the contents of the u_area. The following should work: main(argc, argv) int argc; char **argv; { char *orig_name; if(strcmp(argv[0], "fakename")){ orig_name = argv[0]; argv[0] = "fakename"; execvp(orig_name, argv); /* this will "fool" ps */ } if(!fork()){ execl("/bin/sh", "sh", (char *)0); /* child shell */ return(1); } wait((int *)0); return(0); } Do a 'ps -f' from the child shell and see what you get. -- Lloyd Kremer Brooks Financial Systems ...!uunet!xanth!brooks!lloyd Have terminal...will hack!