my cmd is
putty.exe -ssh -P 6969 -l root -pw 123 -m D:\demo.txt 10.159.106.194
Content in the demo.txt is
tail -f /root/config.ini > /dev/null
I run this cmd and checkout process statuition in linux is ps -ef :
UID PID PPID C STIME TTY TIME CMD
root 68947 1 0 11:02 ? 00:00:00 bash -c tail -f /root/config.ini > /dev/null
root 68970 68947 0 11:02 ? 00:00:00 tail -f /root/config.ini
the tail cmd still running , what can I do to solve this problem?
Then I have a try to change my demo.txt to follow, but did not work:
#!/bin/bash
function sleepH(){
local sshd_pid=$(ps -p $$ -o ppid | tail -n 1)
while true
do
if [[ `ps -p $$ -o ppid | tail -n 1` != $sshd_pid ]];then kill -HUP $$;fi;
sleep 2
done
}
sleepH &
tail -f /root/config.ini >/dev/null
it will run a function in the background to judge sshd if closed, when $$ 's parent ID has changes , like sshd close ,it will run kill -HUP $$, but it did not work. when I run putty , ps -ef :
UID PID PPID C STIME TTY TIME CMD
root 70324 1 0 12:45 ? 00:00:00 sshd: root@notty
root 70327 70324 0 12:45 ? 00:00:00 bash -c #!/bin/bash function sleepH(){ ?local sshd_pid=$(ps -p $$ -o ppid | tail -n 1) ?while true ?do ??if [[ `ps -p $$ -o ppid | tail -n 1` != $sshd_pid ]];t
root 70350 70327 0 12:45 ? 00:00:00 bash -c #!/bin/bash function sleepH(){ ?local sshd_pid=$(ps -p $$ -o ppid | tail -n 1) ?while true ?do ??if [[ `ps -p $$ -o ppid | tail -n 1` != $sshd_pid ]];t
root 70351 70327 0 12:45 ? 00:00:00 tail -f /root/config.ini
when I close putty, it will become ps -ef :
UID PID PPID C STIME TTY TIME CMD
root 70350 1 0 12:45 ? 00:00:00 bash -c #!/bin/bash function sleepH(){ ?local sshd_pid=$(ps -p $$ -o ppid | tail -n 1) ?while true ?do ??if [[ `ps -p $$ -o ppid | tail -n 1` != $sshd_pid ]];t
root 70351 1 0 12:45 ? 00:00:00 tail -f /root/config.ini
root 70387 70350 0 12:45 ? 00:00:00 sleep 2
I am so confused....
I think I find the reason, the process of putty is notty , Usually every process has its own tty,when the terminal exits, all processes belonging to this tty will be killed. But since putty's ssh is not pts, the process will not exit after it exits.
kill -HUP $$
? Does bash exit upon receiving the SIGHUP?