Tradutor

Mostrando postagens com marcador command line. Mostrar todas as postagens
Mostrando postagens com marcador command line. Mostrar todas as postagens

segunda-feira, 18 de maio de 2015

How to find out the current (in use) XServer DISPLAY number!

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







Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Brazil License.