0

我想知道通过 ps 命令、文件或编程从 pid 获取 HPUX 中的环境变量的方法。

有可能得到变量

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

HP-UX : 使用 gdb 进行跟踪,但服务器上没有 gdb (HPUX),无法安装。

让我知道。

4

1 回答 1

1

如果您可以在此主机上安装软件,最新的 HP-UX 链接器、库和工具补丁应该会为您提供以下pargs(1)命令:

[ 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

即使您无法安装补丁,pargs也可以从中提取可执行文件并使用。

如果您可以将文件复制出此主机,则可以

  • 使用gcore(1)生成进程的核心文件
  • 将此核心文件连同可执行文件和适当版本的 libc(32 位或 64 位,使用 pldd(1) 确认)复制到 gdb 可用的环境
  • 使用 gdb 破解 __envp 字符串表

    [ 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:      ""
    
于 2020-03-16T07:50:34.380 回答