Skip to content

Instantly share code, notes, and snippets.

@coproduto
Last active May 16, 2024 14:00
Show Gist options
  • Save coproduto/573064da64b7aaf9f8e166ad8e0e1ffc to your computer and use it in GitHub Desktop.
Save coproduto/573064da64b7aaf9f8e166ad8e0e1ffc to your computer and use it in GitHub Desktop.
#!/bin/bash
trap : SIGTERM SIGINT # : é um noop - só estamos dizendo que queremos receber os sinais
echo $$ # $$ contém o PID do próprio script
find / >/dev/null 2>&1 &
FIND_PID=$! # $! contém o PID do último processo iniciado
wait $FIND_PID # Esperamos até o PID encerrar ou recebermos um sinal
# $? contém o status de retorno do último processo encerrado
# Se o `wait` terminou porque o processo iniciado encerrou, status <= 128
# Já se o `wait` terminou por receber um sinal, status > 128
if [[ $? -gt 128 ]]
then
kill $FIND_PID
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment