8

I have an application that during installation runs a bunch of processes via screen, so I can see those if attached to the screen, however I don't see those via "ps -ef" or "ps auxww". How can I list all the processes running inside of screen ?

Thanks.

3 Answers 3

5
start cmd: # screen -ls
There is a screen on:
        24525.pts-0.syscontrol  (Attached)
start cmd: # pstree -p 24525
screen(24525)─┬─bash(10773)───su(10790)───bash(10791)
              ├─bash(10863)───pstree(11099)
              └─bash(24526)
1
  • Installation of pstree on Linux: apt-get install psmisc (Debian) or yum install psmisc (CentOS) Feb 21, 2020 at 6:23
1

Using pstree greatly simplifies the problem, but some clarification might help.

When you start screen, it runs two processes, screen (the parent) and SCREEN (the child):

  • The -ls option of screen shows the session identifier with the child's process-id.
  • You should list the parent process-id for consistency.
  • It helps to show the argument list; pstree can do this.
  • You could have multiple screen sessions on the same machine.

Tying these together calls for a script. Here is an example:

# $Id: ps-screen,v 1.1 2016/10/23 22:19:56 tom Exp $
# http://unix.stackexchange.com/questions/172347/list-processes-running-inside-of-screen-manager-with-with-vt100-ansi-terminal-e
screen -ls | awk '/[0-9]+\./{print;}' | while read session
do
    child=$(echo "$session" | awk '{sub("\..*","",$1); print $1;}')
    printf '%s\n' "$session"
    parent=$(ps -p $child -o ppid=)
    pstree -p -a $parent
done

and example output, for two sessions:

~ (101) ps-screen 
38142.pts-1.vmw-debian7-64      (10/23/2016 06:20:28 PM)        (Attached)
screen,38141
  └─screen,38142
      └─tcsh,38143
          └─ps-screen,38161 /users/tom/bin/ps-screen
              └─ps-screen,38164 /users/tom/bin/ps-screen
                  └─pstree,38169 -p -a 38141
3975.pts-0.vmw-debian7-64       (10/23/2016 06:15:28 AM)        (Attached)
screen,3974
  └─screen,3975
      ├─tcsh,5002
      │   └─ded,19926 /usr/build//ncurses
      │       └─vile,24647 /usr/build/ncurses/ncurses-6.0-20161029/NEWS
      └─tcsh,36551
          └─ded,36569 /tmp

Further reading:

0

Retrieve tty(pty) from screen -ls and then, ps -t ttyname or ps t ttyname will display process list associated with ttyname.

ps(1) manpage on Ubuntu screen(1) manpage on Ubuntu

You must log in to answer this question.

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