Well, just the hack of the day.
$ ps u | awk -v tty=$(cat /sys/class/tty/tty0/active) '$0 ~ tty { print $2 }' | while read pid && [[ "$display" == "" ]]; do display="$(awk -v RS='\0' -F= '$1=="DISPLAY" { print $2 }' /proc/$pid/environ)"; if [ "$display" != "" ]; then echo "$display"; fi; done 2>/dev/null
:0
Can you improve it? So tell me how. o/
The discussion about the theme on Quora and Linkedin.
Edited with improvement:
http://www.commandlinefu.com/commands/view/14259/find-out-the-active-xorg-server-display-number-from-outside
$ for p in $(pgrep -t $(cat /sys/class/tty/tty0/active)); do d=$(awk -v RS='0' -F= '$1=="DISPLAY" { print $2 }' /proc/$p/environ 2>/dev/null); [[ -n $d ]] && break; done; echo $d
The discussion about the theme on Quora and Linkedin.
__________________________
Edited with improvement:
http://www.commandlinefu.com/commands/view/14259/find-out-the-active-xorg-server-display-number-from-outside
$ for p in $(pgrep -t $(cat /sys/class/tty/tty0/active)); do d=$(awk -v RS='0' -F= '$1=="DISPLAY" { print $2 }' /proc/$p/environ 2>/dev/null); [[ -n $d ]] && break; done; echo $d