Code: Select all
1.sh
Code: Select all
#!/bin/bash
for i in {1..10000}; do
echo "$i in $0"
sleep 1
done
< /code>
2.sh
Code: Select all
#!/bin/bash
./1.sh &
for i in {1..10000}; do
echo "$i in $0"
sleep 1
done
< /code>
Open a terminal:
[list]
[*]run ./2.sh
[*] direkt zu beenden. GREP 1.SH :
[/list]
root 4022351 1 0 19:15 ? 00:00:00 /bin/bash ./1.sh
root 4022492 4022423 0 19:16 pts/5 00:00:00 grep --color=auto 1.sh
< /code>
Why 1.sh is still running?
But if i skip step 2, and close the terminal window directly, 1.sh will also be terminated. why?
----Edit------
This problem is related to https://unix.stackexchange.com/question ... ropagation
- If & operator is used inside non-interactive shell, the decorated process ignores SIGINT/SIGQUIT
- If parent process is terminated before already, for the interactive shell, the job is completed, which leads to NOT sending SIGHUP signal to the & decorated process