Bash nicht nach dem Seufzer enden [Duplikat]Linux

Linux verstehen
Anonymous
 Bash nicht nach dem Seufzer enden [Duplikat]

Post by Anonymous »

Aus dem, was ich von der Linux -Programmierschnittstelle lerne, wenn eine Shell endet, sendet sie das Seufzsignal an alle Prozessgruppen, einschließlich Vordergrund und Hintergrund, wodurch alle von ihnen beendet werden. Das folgende Verhalten widerspricht jedoch Folgendes: < /p>

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
[*] Drücken Sie Strg+C, um 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
Hence, SIGNINT is ignroed and SIGHUP is not sent, resulting in this behavior.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post