而不是从服务中运行nginx。运行service nginx stop,然后运行
strace nginx -g "daemon off;"
这将确保您获得进程的跟踪。 -g "daemon off;" 将确保 nginx 不作为守护进程运行,否则 strace 将再次结束
服务命令只是激活一个进程,如果你想strace它最好是直接启动进程。
如果您仍然对调试使用 service 命令启动的进程感兴趣。然后在下面做
service nginx start
ps aux | grep nginx
从 nginx 进程中捕获pid,然后使用附加到它
strace -p <pid>
分叉进程
要跟踪哪个分叉的进程,您需要使用-f 标志
strace -f nginx
服务追踪
当您调用service start nginx 时,假设系统使用systemd,该调用将转换为systemctl start nginx。现在如果你看systemd的源代码
https://github.com/systemd/systemd/blob/cf45dd36282368d5cdf757cac2cf1fc2b562dab2/src/systemctl/systemctl.c#L3100
r = sd_bus_call_method_async(
bus,
NULL,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"Subscribe",
NULL, NULL,
NULL);
它不会产生/派生进程。它将消息发送到 systemd 服务,然后启动 nginx 进程。
简而言之,NO您无法浏览您的service nginx start 命令。