When kill does not work for a sudo process in a script?
From:
Peng Yu
Subject:
When kill does not work for a sudo process in a script?
Date:
Tue, 2 Mar 2021 00:52:13 -0600
Hi,
When I finish running ./main.sh, the forever.sh sudo process will not
be terminated. But I tried to kill the forever.sh sudo process in
main.sh. But if I remove the two "sudo" words in main.sh, then the
forever.sh process can be terminated.
Does anybody know why the forever.sh sudo process will not be
terminated? Thanks.
==> forever.sh <==
#!/usr/bin/env bash
while true; do
echo "$((++i))"
sleep 1
done
==> main.sh <==
#!/usr/bin/env bash
sudo ./forever.sh &
pid=$!
sleep 5
sudo kill "$!"
--
Regards,
Peng