For example, getting the title of `konsole` window current interactive `bash` instance is running in:
#!/bin/bash
get_title() {
local pid=$$
local pids=`pstree -lpsT $pid | tr '-' '\n' | tac | xargs | grep -oE '[0-9]+'`
for pid in $pids
do
local wid=`xdotool search --pid $pid`
if [ ! -z "${wid}" ]
then
echo `xdotool getwindowname $wid`
exit
fi
done
}
get_title