zoukankan      html  css  js  c++  java
  • 遍历当前系统所有打开读文件

    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <sys/types.h>
    #include <dirent.h>
    #include <fcntl.h>
    
    int main(int argc, char **argv)
    {
    	struct dirent *dirp;
    	DIR *fdir;
    	fdir = opendir("/proc");
    	while(dirp = readdir(fdir)){
    		if(strcmp(dirp->d_name, ".")==0 || strcmp(dirp->d_name, "..") == 0)
    			continue;
    		if(dirp->d_type == DT_DIR) {
    //			printf("%s\n", dirp->d_name );
    //			getchar();
    			char buf[256];
    			sprintf(buf, "/proc/%s/fd", dirp->d_name);
    			DIR *fdir2; 
    			struct dirent *dirp2;
    		       if((fdir2 = opendir(buf)) != NULL ){
    		       		while(dirp2 = readdir(fdir2)){
    					//printf("%s:%s\n", dirp->d_name, dirp2->d_name);
    					char buf2[256];
    					char tmp2[256];
    					sprintf(tmp2, "%s/%s", buf, dirp2->d_name);
    					readlink(tmp2, buf2, 256);
    					printf("%s:\t%s\t%s\n", dirp->d_name, dirp2->d_name, buf2);
    //					getchar();
    				}	
    		       }
    			
    		}
    	}
    
    	
    	return 0;
    }
    
  • 相关阅读:
    python迭代器
    初识html
    跨域(jsonp)方法
    闭包
    pycharm软件配置
    插槽slot
    git常用操作
    在mac中使用Charles抓包操作
    防止网页被嵌入框架
    H5唤起APP
  • 原文地址:https://www.cnblogs.com/mathzzz/p/2657409.html
Copyright © 2011-2022 走看看