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

发布于 2024-11-23 18:07:56 字数 183 浏览 1 评论 0原文

我有大约 25 个运行 PHP 脚本的 Screen 会话。

我如何知道哪些仍在运行从该 Screen 会话启动的 PHP 进程,而不必恢复每个 Screen?我可以使用 screen 或 Linux 的内置功能从命令行访问此信息,还是必须编写脚本来处理此信息?

我从命令行启动屏幕会话并以相同的方式执行 PHP 脚本。

I have about 25 Screen sessions running PHP scripts.

How can I tell which ones are still running the PHP process launched from that Screen session, without having to resume each Screen? 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?

I started my screen sessions from the command line and executed the PHP scripts the same way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

余厌 2024-11-30 18:07:56

如果我没记错的话,当程序运行完毕时,屏幕会话(如果用命令启动,我认为是 -x)将自行终止(屏幕将退出),因此您可以只解析屏幕-list 并查看屏幕(带有您分配的会话名称)是否仍然存在。

或者(我会做什么),您可以在屏幕中启动脚本时向表中添加一个正在运行的行(包含其正在执行的操作、预期完成时间、正在运行的屏幕等信息)。然后,只需让屏幕在完成时从数据库中删除该行,您就可以清楚地看到正在发生的所有事情以及发生的位置。

您甚至可以限制屏幕数量,并在后台运行管理程序以将作业分配给屏幕(在屏幕打开时检查数据库)。

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.

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).

白龙吟 2024-11-30 18:07:56

就我个人而言,我会运行一个 cronjob 或脚本来 ps auxw | grep screen 然后循环遍历每一行,使用 awk 和其他所有不错的工具来查看该 tty 上当前正在运行的内容以及该 tty 的空闲时间...机会是,如果PHP 脚本已完成运行,它将显示该 tty 上没有任何内容正在运行,您可以杀死该屏幕甚至只是 tty ...

Personally, I'd run a cronjob or script that will 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 ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文