您想要实现的目标是可能的,但很难。您需要在适当的用户会话中启动应用程序。出于安全原因,很难跨越用户会话划分。
您需要一个已在其他用户会话中运行的进程来侦听您的请求并代表您启动该应用程序。
推出的bsexec
值得庆幸的是,最新版本的launchd
具备此功能;尽管Apple工程师不建议使用它。使用launchctl中的bsexec
选项定位适当的用户会话:
bslist [PID | ..] [-j]
This prints out Mach bootstrap services and their respective states. While the namespace
appears flat, it is in fact hierarchical, thus allowing for certain services to be only avail-
able to a subset of processes. The three states a service can be in are active ("A"), inactive
("I") and on-demand ("D").
If [PID] is specified, print the Mach bootstrap services available to that PID. If [..] is
specified, print the Mach bootstrap services available in the parent of the current bootstrap.
Note that in Mac OS X v10.6, the per-user Mach bootstrap namespace is flat, so you will only
see a different set of services in a per-user bootstrap if you are in an explicitly-created
bootstrap subset.
If [-j] is specified, each service name will be followed by the name of the job which regis-
tered it.
bsexec PID command [args]
This executes the given command in the same Mach bootstrap namespace hierachy as the given
PID.
bstree [-j]
This prints a hierarchical view of the entire Mach bootstrap tree. If [-j] is specified, each
service name will be followed by the name of the job which registered it. Requires root priv-
ileges.
推荐的方法是编写启动的作业凭单,然后重新启动Mac-或要求用户注销并再次登录。
问题原因
问题源于应用程序连接到错误的WindowServer
进程。每个用户会话都有一个单独的WindowServer。此过程处理用户界面。您以前的方法将进程的所有权分配给正确的用户,但连接到您自己的WindowServer进程。
Apple 的“ 守护程序和代理”技术说明中提到了此问题。
经验
我从个人经验中知道这一点。对于Power Manager,我将pmuser编写为存在于每个用户会话中。pmuser
侦听我们的守护程序并处理每个用户的启动和命令。尽管我们的守护程序具有root权限,但是我们仍然需要每个用户的进程才能在用户会话中可靠地工作。
open
使用命令SSH
?