使用c中的/ proc /文件夹实现ps aux命令[关闭]

问题描述 投票:-1回答:1

我受命使用“ / proc /”文件夹内容在C中编写ps aux命令。

到目前为止,这是我的主要功能,我不知道这是否是我应该检测文件夹是否为进程的方式?我真的不知道如何从这里继续,如何从这些过程的内容中打印ps aux信息?

struct dirent *dp;
char *fullpath;
const char *path="/proc/"; 
DIR *dir = opendir(path); // Open the directory 
DIR *currentDIR;
while (dp=readdir(dir)!==NULL) // once dp is null, there's nothing more to read
{
    /* stuff to print*/
    if(isdigit(dp->d_name)==0){
        currentDIR= opendir("/proc/",dp->d_name,"//")

}


}
closedir(dir); // close the handle (pointer)
return 0;}
c linux proc ps
1个回答
0
投票

/proc/下有很多东西,但是任何带有数字的目录都是进程ID(例如/proc/1234/是PID#1234。

从那里您必须阅读并了解该目录的伪文件under以获取各种信息。 /proc/<pid>/status可能是一个不错的起点。

© www.soinside.com 2019 - 2024. All rights reserved.