Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!rutgers!sri-unix!sri-spam!mordor!lll-tis!ptsfa!ihnp4!occrsh!occrsh.ATT.COM!tiger.UUCP!authorplaceholder From: rjd@tiger.UUCP Newsgroups: comp.unix.wizards Subject: Re: Using argv to show process status Message-ID: <142700017@tiger.UUCP> Date: Tue, 25-Aug-87 14:12:00 EDT Article-I.D.: tiger.142700017 Posted: Tue Aug 25 14:12:00 1987 Date-Received: Fri, 28-Aug-87 04:01:47 EDT References: <1217@mhres.mh.nl> Lines: 51 Nf-ID: #R:mhres.mh.nl:-121700:tiger.UUCP:142700017:000:2019 Nf-From: tiger.UUCP!rjd Aug 25 13:12:00 1987 > I have found out, that the process should execute something like > strcpy (argv[0], "Hi there, I'm doing fine."); > changing argv with > argv[0] = "Hello, world!"; > does not work. > My questions: > - How does this work? Does it work only on BSD type systems, any others? > - Whose memory is the process writing into? What happens if the process > writes more bytes than the caller specified in the command line? > - How can the remainder of the command line be blanked. Filling with a few > null-characters seems not to be sufficient. I'll put in my two cents worth. I did a simple experiment; source: main(argc,argv) int argc; char *argv[]; { strcpy(argv[0],"Q"); system("ps -ef"); } Notice that the new argv[0] is only one character. I had called this program "g", also one character, just so there would be no problem with length mismatch in the character array. Here's the output (greping for just this line, like "./g | grep Q | grep -v grep"): root 19030 6545 5 12:37:29 console 0:00 Q ...so it works... (I always wondered why UUCICO would show up in my process table...this might be the way) This also explains the man page on crypt(1) mentioning that any key entered into the command line would be blanked before execution, but that it was inadvisable to enter the key on the command line (a lucky ps -ef would see the key before it was blanked). Answer #1: This is on AT&T Unix System 5, release 2.0.4 (3B2), don't know about any others. Answer #2: Whose memory? The memory allocated to the process, i.e. yours. What happens if more characters are written than strlen(argv[0])? You overwrite argv[1] or more and screw it all up, i.e. argv[1] will give you last portion of your new argv[0]. If you overwrote more than was originally given (past the end of the argument array), probably more bad things happen, or it just does not work like a "memory error: core dumped", or somesuch. Answer #3: Beats me. Anybody else? Randy (ihnp4!)3b2fst!randy