Skip to content

Instantly share code, notes, and snippets.

@kakash1hatake
Last active May 14, 2020 17:10
Show Gist options
  • Save kakash1hatake/61129d3186079cc1fc680fa523a1551b to your computer and use it in GitHub Desktop.
Save kakash1hatake/61129d3186079cc1fc680fa523a1551b to your computer and use it in GitHub Desktop.
set or replace env variable in existing process. requires root privileges
#!/bin/sh
#
# set or replace env variable in existing process. requires root privileges
# usage: sudo chenv.sh pid var_name var_value
#
pid=$1
env_name=$2
env_val="$3"
out=`gdb -q -batch -ex "attach $pid" -ex 'call (int) setenv("'$env_name'", "'"$env_val"'", 1)' -ex "detach" 2>&1`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment