------------------------------------------------------------------------------- PS command and process handling ------------------------------------------------------------------------------- Simple get pid of a program > pidof sshd 121923 User information of a process USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 121923 0.0 0.0 26508 7428 ? Ss Jul21 0:00 /usr/sbin/ssh Full Command line (no header, wide or no truncation) > ps h -p 121923 -o args -ww /usr/sbin/sshd -D ------------------------------------------------------------------------------- Getting environment (initial environment only) Most programs do not update their runtime environment. That include shells like BASH that does not change their environment, only internally saves what should be passed to new program exec() calls. NOTE: The size of the environment area a process is fixed, and can not be expanded by the program. Though thay can change the contents. Most programs don't do this except say for security, or as an alternative method or reporting status (Like changing their argv arguments - like sendmail) > ps e -p 127887 -ww PID TTY STAT TIME COMMAND 127887 pts/4 Rl+ 261:33 python -u run_model.py test zh_en zh_en_model --del_edges 2 -use_pretrained_embedding XDG_SESSION_ID=2322 HOSTNAME=cockatrice.emperor SHELL=/bin/bash TERM=screen HISTSIZE=1000 SSH_CLIENT=10.0.0.200 47708 22 CONDA_SHLVL=2 CONDA_PROMPT_MODIFIER=(KGM) ... Better to get it from /proc But this only works if you have permission, and you handle 'NUL' separators. # sed 's/\x0/\n/g' /proc/127887/environ #> tr \\0 \\n < /proc/127887/environ xargs -0n1 echo < /proc/$$/environ XDG_SESSION_ID=2322 HOSTNAME=cockatrice.emperor SHELL=/bin/bash TERM=screen HISTSIZE=1000 ... Or extract a specific value > grep -z ^PWD= /proc/127887/environ; echo PWD=/home/bigdata/thomas/chung/Crosslingula-KG-Matching --- To get the CURRENT environment of a process you will need to use "gdb" gdb program pid # THEN Run the following script to dump the environment set variable $foo = (char **) environ set $i = 0 while ($foo[$i] != 0) print $foo[$i++] end -------------------------------------------------------------------------------