0

I want to know the method the way to get environment variable in HPUX from pid by ps command, file, or programming.

it is possible to get variable

# /proc/$pid/environ in environ  or ps e -ww -p $pid in linux
# ps ewww pid in aix
# pargs in solaris

HP-UX : use gdb to track but there is no gdb on a server(HPUX) and it's impossible to install it.

let me know that.

Romeo Ninov
  • 6,538
  • 1
  • 22
  • 31
raphael
  • 1
  • 4

1 Answers1

1

If you can install software onto this host, the latest HP-UX Linker, Libraries and Tools patch should give you the pargs(1) command:

[ hp-ux_ia64 sw ] $ /usr/ccs/bin/pargs -v
HP pstack/pldd/pargs version B.12.67 for HP Itanium(R) Systems.
[ hp-ux_ia64 sw ] $ /usr/ccs/bin/pargs -h

        usage:  pargs [-h] [-v] {-a pid | -e pid}

        Given the pid of a running process, pargs prints process arguments and all
        environment variables and its values.
        pargs works by attaching to the process to read its memory.
[ hp-ux_ia64 sw ] $ ps -fu ranga
     UID   PID  PPID  C    STIME TTY       TIME COMMAND
 ranga  9949  9923  0  Mar 17  pts/3     0:00 /usr/bin/sh /home/ranga/bin/tmux
 ranga 16795 10007  0 10:40:06 pts/7     0:00 ssh hp-ux_ia64
 ranga  9952  9949  0  Mar 17  pts/3     0:00 tmux
 ranga 16538 16376  1 21:35:16 pts/4     0:00 ps -fu ranga
 ranga  9918  9916  0  Mar 17  ?         0:04 sshd: ranga@pts/3
 ranga  9954     1  2  Mar 17  ?         1:15 tmux
[ hp-ux_ia64 sw ] $ PHSS_44731/C-MIN/usr/ccs/bin/pargs -e 9949
SOCKS_CONF=/home/ranga/etc/socks.conf
MAIL=/var/mail/ranga
PATH=/usr/bin:/usr/ccs/bin:/usr/contrib/bin:/opt/langtools/bin:/usr/local/bin
PWD=/home/ranga
EDITOR=vim
TZ=IST-5:30
ERASE=^H
PS1=[ \h \W ] \$
SHLVL=1
SHELL=/usr/bin/bash
SFTP_PERMIT_CHMOD=1
HOME=/home/ranga
TERMINFO=/home/ranga/lib/terminfo
LOGNAME=ranga
SSH_CONNECTION=1.4.5.1 44584 1.2.2.2 22
SSH_CLIENT=1.1.0.6 44584 22
SHLIB_PATH=/home/ranga/local/lib
SFTP_UMASK=
_=/home/ranga/bin/tmux
USER=ranga
TERM=rxvt-256color
SOCKS5_SERVER=socks-server.ranga.com
LINES=70

Even if you can't install the patch, the pargs executable can be extracted from it and used.

If you can copy files out of this host, you could

  • use gcore(1) to generate a core file of the process
  • copy this core file along with the executable and the appropriate version of libc (32-bit or 64-bit, use pldd(1) to confirm) to an environment where gdb is available
  • use gdb to hack into the __envp string table

    [ hp-ux-ia64 ~ ] $ ps -f
         UID   PID  PPID  C    STIME TTY       TIME COMMAND
     ranga    5779  4411  0 13:12:47 pts/0     0:00 ps -f
     ranga    4411  4403  0 12:45:42 pts/0     0:00 -bash
    [ hp-ux-ia64 ~ ] $ pldd 4411
    4411:   /usr/bin/bash
    /usr/bin/bash
    /usr/lib/hpux32/dld.so
    /usr/local/lib/hpux32/libtermcap.so
    /usr/local/lib/hpux32/libintl.so
    /usr/local/lib/hpux32/libiconv.so
    /usr/lib/hpux32/libdl.so.1
    /usr/lib/hpux32/libc.so.1
    [ hp-ux-ia64 ~ ] $ gcore 4411
    [ hp-ux-ia64 ~ ] $ gdb -q /usr/bin/bash core.4411
    
    warning: Load module /usr/bin/bash has been stripped.
    Debugging information is not available.
    
    (no debugging symbols found)...Core was generated by `bash'.
    
    (no debugging symbols found)...
    warning: Load module /usr/local/lib/hpux32/libtermcap.so has been stripped.
    Debugging information is not available.
    
    (no debugging symbols found)...
    #0  0x60000000c05660f0:0 in _waitpid_sys+0x30 () from /usr/lib/hpux32/libc.so.1
    (gdb) x/s *(char**)__envp
    0x200000007ffffeae:      "USER=ranga"
    (gdb)                           
    :                             
    0x200000007fffff45:      "SSH_CLIENT=3.3.3.3 50072 22"
    :
    0x200000007fffffe4:      "SFTP_PERMIT_CHOWN=1"
    (gdb)
    0x200000007ffffff8:      ""
    
ranga
  • 372
  • 1
  • 4