Linux 遍歷讀取/proc目錄下的pid文件夾

#include <dirent.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
    DIR *dp;
    struct dirent *entry;

    dp = opendir("/proc");
    if (dp) {
	    int i = 0;
	    while ((entry = readdir (dp)) != NULL) {
		    if ((strcmp(entry->d_name, ".") == 0) ||
				    (strcmp(entry->d_name, "..") == 0) ||
				    (atoll(entry->d_name) <= 0)) {
			    continue;
		    }
		    printf("d_name : %s\t", entry->d_name);
		    if (++i % 10 == 0) {
			    printf("\n");
		    }
	    }
   	    printf("\n");
        closedir(dp);
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章