如何检查屏幕后台脚本进程?

时间:2015-10-25 01:32:49

标签: linux shell

我在AWS服务器上有后台运行的shell脚本。为此,我使用了以下命令:

apt-get install screen   #Install screen
screen -m                #Start screen
bash myscript.sh         #Run the script
CTRL + a and then d      #Detach and run in background

要检查脚本是否仍在运行,我使用以下命令:

# List the detached screens
screen -ls

# Find the screen to reattach and attach
screen -r 123456

是否有更优雅的方式来查看我的后台脚本是否仍在运行且未挂起或处于错误状态?

1 个答案:

答案 0 :(得分:1)

您可以使用pgrep <process_name>检查您的脚本是否仍在运行。

  

pgrep查看当前正在运行的进程并列出   将选择条件与stdout匹配的进程ID。一切   标准必须匹配。

http://linux.die.net/man/1/pgrep