You are not logged in.

#1 2021-01-20 12:39:03

karabaja4
Member
From: Croatia
Registered: 2008-09-14
Posts: 929

zenity - kill process when cancel is clicked with --progress

Hello,

I'm trying to show pulsating progress bar while the background process is running. When 'Cancel' is clicked, I want the process that was started to be killed.

This is what I have so far:

#!/bin/bash
# shellcheck disable=SC2002

set -euo pipefail

spin() {
    local -r pid="${!}"
    local -r fifo="$(mktemp -u)"
    mkfifo "${fifo}"

    trap 'kill "${pid}"' HUP
    cat "${fifo}" | zenity --progress --pulsate --auto-close --auto-kill --text="${1}" &
    wait "${pid}"
    echo "" > "${fifo}"
    rm -f "${fifo}"
}

sleep 10 &
spin "sleeping"

This is the best I could come up with and this works, but I am wondering if there is a better way to do this without opening a FIFO, because zenity seems to send HUP to the parent which does not kill the process.

Offline

Board footer

Powered by FluxBB