击:守护进程的屏幕会话获取PID
问题描述:
如果我开始一个GNU屏幕会话作为一个守护进程,我将如何检索其PID编程?我不知道屏幕-ls的输出是怎么保持一致,所以我想知道如何使用bash的常量之一, $ , $!或一个更好的选择。
If I start a GNU screen session as a daemon, how would I retrieve its PID programmatically? I don't know how consistent the output of screen -ls is, so I'd like to know how to do this with one of bash's constants, $$, $! or a better alternative.
我开始与屏幕屏幕-dms屏幕名。
我将如何正确之前或者在开始屏幕会议之后立即得到了屏幕的PID?
How would I get the PID of a screen right before or immediately after starting the screen session?
答
这显示了一个名为屏幕PID nameofscreen :
This show the pid for a screen named nameofscreen:
$ screen -ls
There are screens on:
19898.otherscreen (07/03/2012 05:50:45 PM) (Detached)
19841.nameofscreen (07/03/2012 05:50:23 PM) (Detached)
2 Sockets in /var/run/screen/S-sarnold.
$ screen -ls | awk '/\.nameofscreen\t/ {print strtonum($1)}'
19841
$