使用POSIX功能显示所有过程 [英] Display all process using a posix function

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

问题描述

我想显示当前在Ubuntu中运行的进程。

现在我用system()函数来打印正在运行的进程在终端。 code:

 系统(PS -A);

这个功能可以显示所有正在运行的进程在终端。

但我想使用POSIX函数此功能。我不是在寻找一个现成的code。

有人可以点我到函数名称或任何手动?


解决方案

  

但我想使用POSIX函数此功能。我不是在寻找一个现成的code。


没有POSIX函数存在列出正在运行的进程。这是OS具体,不便于携带,通过应用程序很少需要,因而不POSIX的一部分。

不过,因为你需要这在Linux上,最POSIXy的解决办法是使用函数 执行opendir() / READDIR() / closedir()来迭代的/ proc 特殊的文件系统的内容。

在目录中的所有数字项正在运行的进程的PID。检查内容 5人PROC 什么了解正在运行的进程信息,可以从那里获得的详细信息。然后你可以使用的open() / 阅读() / 的close() 的readlink() 调用来检索有关从的/ proc / NNN / * 文件。

特定进程的信息

在Linux中,标准的工具,如 PS 使用 / proc中来收集有关进程的信息。这是官方的Linux的界面来对正在运行的进程的信息。

I am trying to display currently running process in Ubuntu.

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.

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 ?

解决方案

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

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

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.

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.

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天全站免登陆