使用posix函数显示所有进程 [英] Display all process using a posix function

查看:26
本文介绍了使用posix函数显示所有进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Ubuntu 中显示当前正在运行的进程.

I am trying to display currently running process in Ubuntu.

现在我正在使用 system() 函数在终端中打印正在运行的进程.代码:

Right now I am using system() function to print running process in the terminal. Code:

system("ps -A");

该函数显示终端中所有正在运行的进程.

This function displays all running process in the terminal.

但我想使用 POSIX 函数来实现此功能.我不是在寻找现成的代码.

But I want to this functionality using a POSIX function. I am not looking for a ready made code.

有人能指出我的函数名称或任何手册吗?

Can some one point me to the function name or any manual ?

推荐答案

但我想使用 POSIX 函数来实现此功能.我不是在寻找现成的代码.

But I want to this functionality using a POSIX function. I am not looking for a ready made code.

不存在用于列出正在运行的进程的 POSIX 函数.这是特定于操作系统的,不可移植的,应用程序很少需要,因此不是 POSIX 的一部分.

No POSIX function exists to list running processes. That is OS specific, not portable, rarely needed by applications and thus not part of POSIX.

但是因为你在 Linux 上需要这个,所以最 POSIXy 的解决方案是使用函数 opendir()/readdir()/closedir() 迭代/proc 特殊的内容文件系统.

But since you need this on Linux, the most POSIXy solution would be to use functions opendir()/readdir()/closedir() to iterate over the content of /proc special file system.

目录中的所有数字条目都是正在运行的进程的 PID.查看man 5 proc的内容,了解详细信息可以从那里获得有关正在运行的进程的信息.然后你可以使用 open()/read()/close()readlink() 调用以从 /proc/NNN/* 检索有关特定进程的信息 文件.

All numeric entries in the directory are PIDs of running processes. Check the content the man 5 proc for details what information about the running processes can be obtained from there. Then you can use the open()/read()/close() or readlink() calls to retrieve the information about a particular process from the /proc/NNN/* files.

在 Linux 上,pstop 等标准工具使用 /proc 来收集有关进程的信息.是 Linux 官方提供的关于正在运行的进程信息的接口.

On Linux, the standard tools like ps and top use the /proc to gather the information about processes. It is official Linux' interface to the information about running processes.

这篇关于使用posix函数显示所有进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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