|
From: pjhoust <hou...@ro...> - 2017-06-23 16:23:39
|
GIven: RHEL/CENTOS 6 with utilities xwininfo and xev
The following worked for me to create a window destruction notification
function within the script that I used to call gnuplot. Call the function
with the name of your gnuplot graph window (yes, you have to name it and
make sure it's unique) and a process ID (usually that of the shell running
gnuplot) and background it. When it detects that the given window has been
destroyed, it exits sending a SIGUSR1 signal to whatever PID you gave it.
What you do with the signal is up to you but I just do a mass murder.
###############################################################################
#
# NAME
# WinDestroyNotify
#
# SYNOPSIS
# WinDestroyNotify WIN_NAME PID
#
# DESCRIPTION
# Waits for X window given by WIN_NAME to be destroyed then sends
# SIGUSR1 to process given by PID
#
###############################################################################
WinDestroyNotify() {
local WIN_NAME=$1
local NOTIFY_PID=$2
local FIFO="/tmp/WinDestroyNotify.$$.fifo"
local winid_regex=".*id: ([^ ]*) .*"
local WIN_ID=
local LOOP_PID=
local XEV_PID=
[[ "$(xwininfo -name "$WIN_NAME" )" =~ ${winid_regex} ]] &&
WIN_ID=${BASH_REMATCH[1]}
mkfifo $FIFO >/dev/null 2>&1
while read line
do
[[ $line =~ Destroy ]] && exit
done <$FIFO &
LOOP_PID=$!
xev -id $WIN_ID > $FIFO &
XEV_PID=$!
wait $LOOP_PID
kill $XEV_PID >/dev/null 2>&1
rm -f $FIFO >/dev/null 2>&1
kill -USR1 $NOTIFY_PID >/dev/null 2>&1
}
--
View this message in context: http://gnuplot.10905.n7.nabble.com/Quit-gnuplot-when-plot-window-is-closed-tp1633p20695.html
Sent from the Gnuplot - User mailing list archive at Nabble.com.
|