I have the PID for the process (and the name), I want to bring it to the front on linux (ubuntu). On mac I would simply do SetFrontProcess(pid), on windows I\'d
I thought this would be easy since /proc seemingly has the required data but /proc/${pid}/environ doesn't provide the correct window ID since it is usually the child of the parent who really owns the window where the process is running. To get the proper windowid you need to parse the xwininfo output then you can use xdotool to change the focus.
CMD_PID= && while IFS= read -r -d '' var; do
if grep -q "^WINDOWID=" <<< "$var"; then
winid=$(printf '0x%x\n' $(sed 's/WINDOWID=//' <<< "${var}"))
child_cnt=0 && IFS=$(echo -en "\n\b") && for a in $(xwininfo -root -tree | tac | sed -n "/${winid}/,\$p"); do
grep -q -i "children" <<< "${a}" && let child_cnt+=1
((${child_cnt} == 2)) && real_winid=$(grep -o '0x[^ ]*' <<< "${last_line}") && break
last_line="${a}"
done
xdotool windowraise ${real_winid}
break
fi
done < /proc/${CMD_PID}/environ