Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我希望在 linux 服务器中启动一个 web 应用程序——然后使用 top 命令定期监控它的性能。
然而,top 需要 pid(用于获取特定应用程序/进程的统计信息)——我想知道的是,是否可以通过编程方式获取 pid?这样,我通过 SSH 登录到该服务器,运行 shell 命令来确定该进程的 PID,最后运行 shell 命令以将该 PID 作为参数传递给 top?
哪种编程语言?
尝试
ps -ef | awk '{if ($8 ~ /<nameOfApp>/) print $2;}' > /tmp/tmpFile_
然后您可以从 tmpFile_ 读取 PID 并调用
top -p <PID>