home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.sys.sun.apps:3068 comp.unix.programmer:6032 comp.unix.internals:2151
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!pyrite!edvax
- From: edvax@pyrite.som.cwru.edu (Ed Reznichenko)
- Newsgroups: comp.sys.sun.apps,comp.unix.programmer,comp.unix.internals
- Subject: modifying ARGV within a running program
- Date: 23 Jan 1993 06:11:35 GMT
- Organization: WSOM CSG, CWRU, Cleve. OH
- Lines: 33
- Distribution: world
- Message-ID: <1jqninINNa8l@usenet.INS.CWRU.Edu>
- NNTP-Posting-Host: pyrite.som.cwru.edu
- X-Post-Machine: pyrite.som.cwru.edu
-
-
-
- Platform: SunOS4.1
- Hardware: SPARC IPC
-
- Hi,
-
- Does anyone know how to SAFELY modify (i.e. change) the argument vector inside
- a running program so that when you do a ps it is picked up. I.e. I think
- the C-runtime crt0.o sets up argv[0]...argv[n] on the stack followed by
- the actual strings. But once a program is execve'd, I can't seem
- to realloc/malloc that area. I got it to work for the case where you
- specify sufficiently long arguments to the program and then overwrite them.
-
- The example below demonstrates what I do:
-
- you invoke your program (called xyz) with arguments abc def:
- xyz abc def
- but you want ps auxww, to show FOO arg0 arg1, so:
-
- sprintf(argv[-1],"FOO arg0 arg1");
-
- for some reason I have to put argv[-1], because argv[0] maps to argv[1]
- when I do a ps. This seems to work but I do not feel secure enough about it.
- Any ideas on how to do this portably (if at all) would be appreciated.
-
- Thanks,
-
- --ed
-
-
- --
- Bus error, core dumped
-