如何从其pid获取过程详细信息 [英] How to get process details from its pid

查看:87
本文介绍了如何从其pid获取过程详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从现在开始,我已经维护了当前在我的系统(Linux)上运行的进程的pid列表,如果我可以从此pid中获取进程详细信息,那我就很高兴了,我已经在golang中通过syscall.Getrusage()了,但是我没有得到理想的结果.有人有与之相关的想法

I have maintained a list of pids of processes currently running on my system(Linux) from this now it would be great if i can get the process details from this pid i have come over syscall.Getrusage() in golang but i am not getting desired results. Does anyone have idea related to it

推荐答案

这可能不是要求者所要的(关于每个进程ID所需的详细信息类型,信息不多),但是您可以获得一些信息使用BASH命令 ps -p $ PID ( ps 进程状态的缩写)通过任务的pid来显示任务的详细信息

This might not be exactly what the asker wanted (there's not much clear info on what type of details are required for each process id), but you can get some details of a task by its pid using the BASH command ps -p $PID (ps being short for process status)

默认选项为 ps -p $ PID ,则返回:

  • PID:回显进程ID
  • TTY:控制终端的名称(如果有)
  • TIME:自执行以来,该进程使用了​​多少CPU时间(例如00:00:02)
  • CMD:调用该进程的命令(例如 java )

可以使用-o options标志显示有关该进程ID的更多信息.有关列表,请参见此文档页面.

More information about this process id can be shown using the -o options flag. For a list, see this documentation page.

这里是一个示例,它告诉您特定的过程PID的完整命令,其中包含参数,用户,组和内存使用情况(请注意,多个-o标志如何成对使用,以及该命令如何使用大量空白填充输出):

Here's one example that tells you a particular process PID's full command with arguments, user, group and memory usage (note how the multiple -o flags each take a pair, and how the command outputs with lots of whitespace padding):

ps -p $PID -o pid,vsz=MEMORY -o user,group=GROUP -o comm,args=ARGS

提示:对于控制台中供人读取的输出,请将args设为最后一个选项-它通常是最长的,否则可能会缩短.

Tip: for human-read output in the console, make args the last option - it'll usually be the longest and might get cut short otherwise.

这篇关于如何从其pid获取过程详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆