Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include <string.h>
- #include<stdlib.h>
- #include<unistd.h>
- #include<dirent.h>
- #include <errno.h>
- #include<sys/types.h>
- #include <sys/stat.h>
- #include<fcntl.h>
- #define BUFF 1024
- void fun(char *name)
- {
- /*struct stat path_stat;
- stat(name, &path_stat);
- if(S_ISDIR(path_stat.st_mode))
- {
- chdir(name);
- }
- */
- char buf[BUFF];
- char buff[BUFF], buf2[BUFF];
- //printf("\n%s",name);
- //printf(getcwd(buf2,sizeof(buf)));
- strcpy(buf2,"/proc/");
- strcat(buf2,name);
- //printf("\n%s",buf2);
- chdir(buf2);
- //printf("\t%s",getcwd(buf,sizeof(buf)));
- int n = open("stat",O_RDONLY);
- //printf("\n%s",buf2);
- //printf(getcwd(buf,sizeof(buf)));
- int no;
- //printf(getcwd(buf,sizeof(buf)));
- while((no=read(n,buff,BUFF))>0)
- {
- char *token;
- int count = 0;
- token = strtok(buff," ");
- //printf("%s\n",token);
- while(token != NULL && count!=2 )
- {
- printf("%s\n",token);
- token = strtok(NULL," ");
- count++;
- }
- }
- }
- int main()
- {
- char buf[BUFF];
- DIR *dirstream;
- struct dirent *d;
- /*char *pwd;
- pwd = getcwd(buf,sizeof(buf));
- */
- chdir("/proc");
- if(getcwd(buf,sizeof(buf))!=NULL)
- {
- if((dirstream=opendir(buf))!=NULL)
- {
- while((d=readdir(dirstream))!=NULL)
- {
- if(isdigit((d->d_name)[0]))
- {
- fun(d->d_name);
- }
- }
- }
- else
- {
- printf("Error.");
- exit(1);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement