1

这是我想用伪代码做的事情:

    create process 
    {
        while not (answer == yes in parent process)
        {
            mplayer alert.mp3
        }
    }

    show dialog "Time is up! Press 'yes' to stop the alarm."
    answer = get userinput

这是我最终使用的代码:

    #!/bin/bash

    sleep $1
    lockfile=$(mktemp)
    {
        while [[ -f "$lockfile" ]]
        do
            kdialog --passivepopup 'Time is up!' 1
            sleep 1
        done
    }&

    kdialog --msgbox 'Time is up! Leave this dialog to stop notifications.'
    rm $lockfile

感谢@abeaumet

4

1 回答 1

1

由于您要共享的变量似乎是一个布尔值,您可以根据是否存在临时文件来确定自己。

带有以下代码的具体示例:

#!/bin/sh

# Create a lock file to permit communication (act as your bool variable)
LOCKFILE=`mktemp /tmp/scriptXXXX`

# Fork a subprocess in background
{
  # While the lockfile exists, wait
  while [ -f "$LOCKFILE" ] ; do sleep 1 ; done

  # When the file no longer exists, this is the signal from the main process
  echo 'File removed! Play music!'
} &

# Do some long stuff in main process...
sleep 5

# Delete the lockfile (child wait for it)
rm -f "$LOCKFILE" &>/dev/null

exit 0
于 2013-05-23T12:32:28.667 回答