0

screen -ls does not seem to indicate how many connections I have using screen -x (multi display mode).

Example:

screen     # create first screen
screen -ls
screen -x  # attach to first screen from a different location
screen -ls 

Both screen -ls commands show the exact same info. There's no indication that there is now 2 attachments to the same screen. Is there a way to show this?

1 Answer 1

1

screen -ls will not list it, but you can find out the number of attached screens by looking at the pts devices created for the master process.

The script below will add a number to the end of screen -ls with the number of attached screens:

#!/bin/bash

screen -ls | while read scr
do
    if [[ "$scr" =~ ^[0-9]+\. ]]; then
        pid=${scr%%.*}
        cnt=$(ls -l /proc/$pid/fd/ | grep pts | wc -l)
        echo "$scr [$cnt]"
    else
        echo "$scr"
    fi
done
1
  • This is an amazing answer! Thank you, it worked perfectly! The key to this is ls -l /proc/$pid/fd/ | grep pts, where $pid is the pid for screen if you want to see how it works.
    – wisbucky
    Feb 14, 2020 at 18:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .