php - 如何在mac/usr/bin/nohup上执行

标签 php linux macos

我正在尝试使用 nohup 在 mac 上创建进程。进程已创建,但创建后立即终止。该进程有命令/usr/bin/wget http://local.domain/some.php .这是来自/var/log/system.log 的错误

(0x7fed9c80a940.anonymous.nohup[23454]): Bug: 12E55: launchd + 67394 [7DCC9489-2DF5-3807-83FA-EF5666EE8078]: 0x0
(0x7fed9c80a940.anonymous.nohup[23454]): Switching sessions is not allowed in the system Mach bootstrap.
(0x7fed9c80a940.anonymous.nohup[23454]): _vprocmgr_switch_to_session(): kr = 0x44c

我已经坚持了几天了。

进程在 linux 上创建和执行都很好。

最佳答案

我认为这是上下文的问题。 OsX 不是 Linux,它基于 BSD,但它不仅仅是一个克隆/发行版。在它的核心部分,有这个 Mach 内核,它为您提供 DOS(如拒绝服务)处理。我从这一行得到这个:

Switching sessions is not allowed in the system Mach bootstrap

我认为,问题在于 Mach 处理 Bootstrap 上下文的方式。 nohup 暗示执行的命令可以/可能在您的情况下在注销后继续存在。使用 wget 时,这不会计算:

In Mach, the bootstrap task is assigned responsibility for looking up requests for Mach ports. As part of this effort, each Mach task is registered in one of two groups—either in the startup context or a user’s login context

你在登录上下文中使用 nohup fork 一个 child ,这是我上次检查的,注销后清理(某种自动释放池风格)。这真的行不通,对吗?
更重要的是:您正在处理响应请求的 PHP,但与此同时, fork 的子进程可能比管理这些请求的上下文更长寿。因此,这会影响 nohup 的使用:

Contexts also pose an issue for users running background jobs with nohup or users detaching terminal sessions using screen. There are times when it is perfectly reasonable for a program to survive past logout, but by default, this does not occur.

基本上,因为您是从登录上下文运行进程,所以任何子进程都会自动在相同(登录)上下文中运行。在您的情况下,您对子进程负责,但 nohup 暗示它可能比您的上下文更长寿,没有人对该进程负责,这可能是有害的。它需要上下文启动。这有点冒险。我还没有找到明确的解决方法,su[do] 没有帮助,因为这对上下文没有影响。
我能想到的唯一方法是让你编写一个在启动上下文中运行的脚本/守护进程,然后空闲,等待你将命令传递给它,因为在启动上下文中运行的任何守护进程都会在其自己的(启动)上下文。无论如何,我想这就是 httpd 的工作方式

要么那样,要么创建第三个上下文,但我无法告诉您如何安全地这样做...

来源:OSX Kernel programming guide

关于php - 如何在mac/usr/bin/nohup上执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17746158/

相关文章:

php - 使用 IN 通过数组搜索数据库

php - 在PHP中,为什么会出现 “class name must be a valid object or string”错误?

linux - 如何跟踪写入同一日志文件的多个线程

linux - 即使页面不存在,Wget 也会创建输出文件

macos - mac下如何创建透明窗口?

macos - Cocoa osx PDFView NSPrintOperation PrintPanel 不显示页面预览

php - ReflectionObject vs. cast to array vs. get_object_vars 用于检索公共(public)变量

php - 是否可以在选择值后添加添加数字?

linux - 如何使用 ExtUtils::MakeMaker 在自定义目录中安装数据

javascript - 在 Electron 渲染器进程中显示 .icns 文件