Why Perl here ?

Jay Kulpinski jskulpin "at" eng01.psf.lmco.com
Fri, 27 Mar 1998 13:42:29 +0000


alexandre.ferrieux "at" cnet.francetelecom.fr wrote:
> 
> 
>  Good point.   On a unix box, it is really infrequent to have multiple
> displays installed. Worse, these may be  stale TCP binds from previous
> invocations of  Xvnc which did not exit fully  !   So I think 'hiding'
> the  problem of finding  a  free  X port (above 6000) is a really  bad
> idea.
> 
>  In  any  case, as an exercise, we can start a thread on this isolated
> problem of finding free TCP port with vanilla shells. We know  already
> two possibilities:
> 
>          Robert> upping the [port number] by 1 after each failure.
>          Alex>   using netstat
> 
>          ... any other suggestions ?
> 
> -Alex

# -------------------------------
#   search for a usable display
# -------------------------------
for i in 0 1 2 3 4 5 6 7 8 9
do
   lock=/tmp/.X${i}-lock
   # second half of test here is a Linux-specific check to see if 
   # the process indicated in the lock file is still running
   if [ ! -f $lock ] || [ ! -d /proc/`sed 's/ //g' $lock` ]
   then
      display=$i
      break
   fi
done