Last active
August 23, 2023 12:07
-
-
Save thejohnfreeman/cfd5e3f6f74120d05db31088bfda839d to your computer and use it in GitHub Desktop.
terminate background sudo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
psudo() { | |
sudo --validate | |
dir=$(mktemp -d) | |
mkfifo ${dir}/pipe | |
sudo sh -c "echo \$\$ >${dir}/pipe; exec $*" & | |
pid=$(cat ${dir}/pipe) | |
rm -rf ${dir} | |
} | |
sudo --validate | |
echo "start" | |
sudo sleep 100 & | |
echo $! | |
pstree -pT $! | |
ps $! | |
for signal in SIGTERM; do | |
echo ${signal} | |
kill -${signal} $! | |
echo $? | |
pstree -pT $! | |
if ! ps $!; then | |
break | |
fi | |
done | |
echo "wait" | |
time wait $! | |
echo $? | |
pstree -pT $! | |
ps $! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start | |
3479154 | |
sudo(3479154)───sudo(3479156)───sleep(3479157) | |
PID TTY STAT TIME COMMAND | |
3479154 pts/12 S+ 0:00 sudo sleep 100 | |
SIGTERM | |
0 | |
PID TTY STAT TIME COMMAND | |
wait | |
real 0m0.000s | |
user 0m0.000s | |
sys 0m0.000s | |
143 | |
PID TTY STAT TIME COMMAND |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment