[comp.unix.wizards] changing cmd listing for ps -f

kiick@b11.ingr.com (chris kiick) (06/30/90)

How can I change the command name that ps -f lists from within
 a program?  What I'm trying to do is to fork off a process that will
 look different to a person doing a ps -f.  Changing argv doesn't
 seem to do it. Any Ideas?

thanks.

***********************************************************
      Chris J. Kiick       | work phone: (205) 730-6171
   Programmer at Large     | Email: ingr!b11!marvin!kiick
 "Ideas for sale, Cheap!"  | 
 
***********************************************************

sar0@cbnewsl.att.com (stephen.a.rago) (07/02/90)

In article <8259@b11.ingr.com>, kiick@b11.ingr.com (chris kiick) writes:
> How can I change the command name that ps -f lists from within
>  a program?  What I'm trying to do is to fork off a process that will
>  look different to a person doing a ps -f.  Changing argv doesn't
>  seem to do it. Any Ideas?

Try copying the command to a different name and, when the command
starts, have it look at argv[0].  If it's the original name, then exec
the other copy.

etxtorn@juno11.ericsson.se (Thomas Tornblom TM/JU 99367) (07/03/90)

In article <8259@b11.ingr.com> kiick@b11.ingr.com (chris kiick) writes:
>How can I change the command name that ps -f lists from within
> a program?  What I'm trying to do is to fork off a process that will
> look different to a person doing a ps -f.  Changing argv doesn't
> seem to do it. Any Ideas?
>
>thanks.
>
>***********************************************************
>      Chris J. Kiick       | work phone: (205) 730-6171
>   Programmer at Large     | Email: ingr!b11!marvin!kiick
> "Ideas for sale, Cheap!"  | 
> 
>***********************************************************

I guess you're running system V of some flavor.
System V:s ps has some sanity checking built in that wont let you just
change the argv pointers. The pointers are checked so that they don't
point "too low" in memory. One way of circumventing this is to copy
the strings in place (strcpy), not just changing the pointers. This can
be a bit tricky though as you have to check so that you don't run off the
old strings.

Thomas

boyd@necisa.ho.necisa.oz (Boyd Roberts) (07/04/90)

Nothing you do on System V will change the command name/argument list
that ps prints.  Both the command name and some of the `arguments' are
stored in the U area and are not modifiable by any `reliable' method.

Check out u.u_comm and u.u_psargs in /usr/include/sys/user.h.  ps uses
these U area values alone.  No longer does it search the user process'
stack.  That was always `messy'.

That's the story on V.2 and I guess it's the same on V.n for n > 2.


Boyd Roberts			boyd@necisa.ho.necisa.oz.au

``When the going gets wierd, the weird turn pro...''

sar0@cbnewsl.att.com (stephen.a.rago) (07/05/90)

In article <1793@necisa.ho.necisa.oz>, boyd@necisa.ho.necisa.oz (Boyd Roberts) writes:
> Nothing you do on System V will change the command name/argument list
> that ps prints.  Both the command name and some of the `arguments' are
> stored in the U area and are not modifiable by any `reliable' method.

except exec(2)...

friedl@mtndew.UUCP (Stephen J. Friedl) (07/05/90)

In article <1793@necisa.ho.necisa.oz>, boyd@necisa.ho.necisa.oz (Boyd Roberts) writes:
> Nothing you do on System V will change the command name/argument list
> that ps prints.  Both the command name and some of the `arguments' are
> stored in the U area and are not modifiable by any `reliable' method.

The industrious can find an unreliable but fun method.  At the
start of your program, make a pipe.  Write all your real args
down the pipe and then modify the arg list to taste but with some
magic word as argv[0] so the program knows that it's on the
second round.  I usually use the empty string.  Then close the
write half of the pipe and exec yourself (finding your own name
could be hard).

On the second round you look for the magic token in argv[0].  If
found, open /dev/null and then close it again: the read pipe will
be one less than the descriptor returned.  Read all your args
from it and stick them back in whatever argv you want to work
with, close the pipe, and continue.

Now ps will show the arglist you want.

Yes, it is an unreliable hack but I felt kind of clever when I
thought of it :-)

     Steve

-- 
Stephen J. Friedl, KA8CMY / Software Consultant / Tustin, CA / 3B2-kind-of-guy
+1 714 544 6561  / friedl@mtndew.Tustin.CA.US  / {uunet,attmail}!mtndew!friedl

"Show me a good loser and I'll show you a loser" - Roger Penske

boyd@necisa.ho.necisa.oz (Boyd Roberts) (07/09/90)

In article <1990Jul4.215854.14916@cbnewsl.att.com> sar0@cbnewsl.att.com (stephen.a.rago) writes:
>In article <1793@necisa.ho.necisa.oz>, boyd@necisa.ho.necisa.oz (Boyd Roberts) writes:
>> ... and are not modifiable by any `reliable' method.
>
>except exec(2)...

Perhaps I should have said `reliable, sane method'.


Boyd Roberts			boyd@necisa.ho.necisa.oz.au

``When the going gets wierd, the weird turn pro...''