A quick mental dump in case I forget it again next time. First, check your PID
:
$ ps faux | grep 'your_process'
508 28818 0.0 0.3 44704 3584 ? Sl 10:10 0:00 \_ /path/to/your/script.sh
Now, using that PID
(in this case, 28818), check the environment variables in /proc/$PID/environ
.
$ cat /proc/28818/environ
TERM=linuxPATH=/sbin:/usr/sbin:/bin:/usr/binrunlevel=3RUNLEVEL=3SUPERVISOR_GROUP_NAME=xxxPWD=/path/to/your/homedirLANGSH_SOURCED=1LANG=en_US.UTF-8previous=NPREVLEVEL=N
Now to get that output more readable, you can do two things. Either parse the null character (\0
) and replace them by new lines (\n
) or use the strings
tool that does this for you.
Let’s take the hard path first, to see what’s going on.
$ cat /proc/28818/environ | tr '\0' '\n'
TERM=linux
PATH=/sbin:/usr/sbin:/bin:/usr/bin
runlevel=3
RUNLEVEL=3
SUPERVISOR_GROUP_NAME=xxx
PWD=/path/to/your/homedir
LANGSH_SOURCED=1
LANG=en_US.UTF-8
previous=N
PREVLEVEL=N
Alternatively, you can use strings
directly on the file.
$ strings /proc/28818/environ
TERM=linux
PATH=/sbin:/usr/sbin:/bin:/usr/bin
runlevel=3
RUNLEVEL=3
SUPERVISOR_GROUP_NAME=xxx
PWD=/path/to/your/homedir
LANGSH_SOURCED=1
LANG=en_US.UTF-8
previous=N
PREVLEVEL=N
Reference
- https://ma.ttias.be/show-the-environment-variables-of-a-running-process-in-linux/
- https://serverfault.com/questions/66363/environment-variables-of-a-running-process-on-unix
FEATURED TAGS
algorithm
algorithmproblem
architecturalpattern
architecture
aws
c#
cachesystem
codis
compile
concurrentcontrol
database
dataformat
datastructure
debug
design
designpattern
distributedsystem
django
docker
domain
engineering
freebsd
git
golang
grafana
hackintosh
hadoop
hardware
hexo
http
hugo
ios
iot
java
javaee
javascript
kafka
kubernetes
linux
linuxcommand
linuxio
lock
macos
markdown
microservices
mysql
nas
network
networkprogramming
nginx
node.js
npm
oop
openwrt
operatingsystem
padavan
performance
programming
prometheus
protobuf
python
redis
router
security
shell
software testing
spring
sql
systemdesign
truenas
ubuntu
vmware
vpn
windows
wmware
wordpress
xml
zookeeper