简体   繁体   English

如何从命令行判断哪些 Screen 会话仍在运行 PHP 进程?

[英]How can I tell which Screen sessions are still running a PHP process from the command line?

I have about 25 Screen sessions running PHP scripts.我有大约 25 个屏幕会话运行 PHP 脚本。

How can I tell which ones are still running the PHP process launched from that Screen session, without having to resume each Screen?如何判断哪些仍在运行从该屏幕 session 启动的 PHP 进程,而无需恢复每个屏幕? Can I access this information from the command line with built in functionality of screen or linux, or do I have to write scripts to handle this?我可以从命令行使用屏幕或 linux 的内置功能访问这些信息,还是我必须编写脚本来处理这个?

I started my screen sessions from the command line and executed the PHP scripts the same way.我从命令行启动了我的屏幕会话,并以同样的方式执行了 PHP 脚本。

If my memory serves me right, a screen session (if started with a command, I think it is -x) will kill itself (the screen will exit) when the program is finished running, so you could just parse the screen -list and see if the screen (with the session name you assigned it) is still there.如果我的 memory 对我有用,则屏幕 session(如果以命令启动,我认为是 -x)会在程序完成运行时杀死自己(屏幕将退出),因此您只需解析screen -list和看看屏幕(您分配给它的 session 名称)是否仍然存在。

Alternatively (and what I would do) you could add a running row to a table when the script is started in the screen (with information like what it is doing, expected completion time, screen it's running on etc).或者(以及我会做什么)当脚本在屏幕中启动时,您可以在表格中添加一个运行行(包含它正在做什么、预期完成时间、正在运行的屏幕等信息)。 Then just have the screen delete the row from the database when it completes, and you have a nice view of everything that is going on, and where it's happening.然后,当它完成时,只需让屏幕从数据库中删除该行,您就可以很好地了解正在发生的一切以及发生的位置。

You could even limit the number of screens, and have an administration program run in the background to assign jobs to screens (checking the database for when a screen is open).您甚至可以限制屏幕的数量,并在后台运行管理程序以将作业分配给屏幕(检查数据库何时打开屏幕)。

Personally, I'd run a cronjob or script that will ps auxw | grep screen就个人而言,我会运行一个 cronjob 或脚本来ps auxw | grep screen ps auxw | grep screen and then loop through each line, using awk and every other nice tool to see what is currently running on that tty and the idle time of that tty... chances are, if the PHP script has finished running, it will show that there is nothing running on that tty and you can kill that screen or even just the tty... ps auxw | grep screen然后循环遍历每一行,使用awk和其他所有不错的工具来查看当前在该 tty 上运行的内容以及该 tty 的空闲时间......如果 Z2FEC392304A5C73AC138DA228 脚本已完成运行,则可能是,那个 tty 上没有运行任何东西,你可以杀死那个屏幕,甚至只是 tty ......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM