Search code examples
linuxbashsessionpidgnu-screen

Getting the PID of just started screen session


how do you get the PID of a just created screen session like:

screen -dm -S test ping localhost

screen -ls
There is a screen on:

3310.test       (09/04/15 14:07:41)     (Detached)

I want 3310

I was looking at Bash: Getting PID of daemonized screen session but it didn't suit what I needed.

what I have been trying

screen -dm -s test ping localhost | echo $! 

but the pid was off by two or one


Solution

  • Try that:

    screen -dm -S test ping localhost & echo $!
    

    It starts the screen process in the background (screen with -d starts anyway in "detachted mode") and prints its PID.