使用posix函数显示所有进程

编程入门 行业动态 更新时间:2024-10-28 13:18:43
本文介绍了使用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 上,ps 和 top 等标准工具使用 /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函数显示所有进程

本文发布于:2023-10-09 09:29:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1475364.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   进程   posix

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!