Linux API 列出正在运行的进程? [英] Linux API to list running processes?

查看:51
本文介绍了Linux API 列出正在运行的进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个 C/C++ API,它允许我列出 Linux 系统上正在运行的进程,并列出每个进程打开的文件.

I need a C/C++ API that allows me to list the running processes on a Linux system, and list the files each process has open.

不想最终直接读取/proc/文件系统.

I do not want to end up reading the /proc/ file system directly.

谁能想出办法做到这一点?

Can anyone think of a way to do this?

推荐答案

http://procps.sourceforge.net/

http://procps.cvs.sourceforge.net/viewvc/procps/procps/proc/readproc.c?view=markup

是ps等处理工具的来源.他们确实使用 proc (表明它可能是传统和最好的方式).他们的来源是相当可读的.文件

Is the source of ps and other process tools. They do indeed use proc (indicating it is probably the conventional and best way). Their source is quite readable. The file

/procps-3.2.8/proc/readproc.c

可能有用.ephemient 发布的另一个有用的建议是链接到 libproc 提供的 API,它应该在您的存储库中可用(或者我会说已经安装),但您需要标题和其他内容的-dev"变体.

May be useful. Also a useful suggestion as posted by ephemient is linking to the API provided by libproc, which should be available in your repo (or already installed I would say) but you will need the "-dev" variation for the headers and what-not.

祝你好运

这篇关于Linux API 列出正在运行的进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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