Codice per sapere se il processo è ancora attivo: (esempio con lftp)
Code:
function lftp-sleep () {
# Get PIDs of running lftp processes
PIDS="$(pidof lftp)"
if [ -z "$PIDS" ]; then
echo "Error: lftp not running!" >&2
return 1
fi
# Wait for PIDs to finish
for PID in $PIDS; do
while [ -f /proc/$PID/cmdline ] && [ "$(head -c5 /proc/$PID/cmdline)" == "lftp"$'\0' ]; do
sleep 10s;
done
done
# Shutdown
echo "lftp-sleep: Shutting down." >&2
logger "lftp-sleep: Shutting down."
shutdown -h now
}