Bash: the sleep process is not killed

I wrote a simple bash script that does nothing but sleeps.

#!/bin/bash

echo "Sleeping..."
sleep 180s

I see two processes running on my system after running the script:

user 22880  0.0  0.0  12428  1412 pts/28   S+   20:12   0:00 /bin/bash ./sleep.sh
user 22881  0.0  0.0   7196   356 pts/28   S+   20:12   0:00 sleep 180s

I pass to the SIGTERMprocess with id 22880using kill -15 22880, which kills the process. However, after that, I still see that the sleep command is executing, which completes after 180 seconds.

user 22881  0.0  0.0   7196   356 pts/28   S    20:12   0:00 sleep 180s

Why is this happening? What do I need to do to stay in the process sleep 180s?

+4
source share
2 answers

kill -15 22880 , script, sleep. , .

kill -15 -22880

, script .

trap 'kill $(jobs -p)' EXIT
echo "Sleeping..."
sleep 180s & wait

sleep , , , ; sleep . - , wait . wait, , , , .

+5

killall sleep kill -9/15 $(pidof sleep)

9 , , 15

ps -ef|grep sleep pratik 24775 2695 0 23:44 pts/0 00:00:00 sleep 600 pratik 24778 24690 0 23:44 pts/29 00:00:00 grep --color=auto sleep killall sleep ps -ef|grep sleep pratik 24792 24690 0 23:44 pts/29 00:00:00 grep --color=auto sleep

ps -ef|grep sleep pratik 24978 2695 0 23:52 pts/0 00:00:00 sleep 600 pratik 24981 24690 0 23:52 pts/29 00:00:00 grep --color=auto sleep kill -15 $(pidof sleep) ps -ef|grep sleep pratik 24986 24690 0 23:52 pts/29 00:00:00 grep --color=auto sleep

+1

Source: https://habr.com/ru/post/1621475/


All Articles