Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<sys/types.h>
- #include<sys/stat.h>
- #include<alloca.h>
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #include<limits.h>
- #include<unistd.h>
- #include<dirent.h>
- #include<pthread.h>
- int countProc = 0;
- pthread_t tId[500];
- char *findPath;
- int maxProc;
- void *Process(void *curPath){
- DIR *dp;
- dp = opendir((char *)curPath);
- struct dirent *d;
- struct stat buf;
- char *filePath = alloca(strlen(curPath) + NAME_MAX + 2);
- int fileCounter = 0;
- d = readdir(dp);
- while(d){
- if(strcmp(".", d->d_name) != 0 && strcmp("..", d->d_name) != 0){
- strcpy(filePath, curPath);
- strcat(filePath, "/");
- strcat(filePath, d->d_name);
- if(d->d_type != DT_DIR){
- if(strcmp(d->d_name,findPath) == 0){
- stat(filePath, &buf);
- printf("%s\n","\n///////////////////////////////////////////RESULT///////////////////////////////////////////////////\n");
- printf("Path = %s, Size = %ld, Date = %d,Access Rights = %o, id = %d\n", filePath, buf.st_size, buf.st_ctime, buf.st_mode, buf.st_ino);
- printf("%s\n","\n//////////////////////////////////////////////////////////////////////////////////////////////////////\n");
- }
- fileCounter++;
- }
- if(d->d_type == DT_DIR){
- if(countProc<maxProc){
- pthread_create(&tId[countProc], NULL, Process, filePath);
- countProc++;
- pthread_join(tId[countProc - 1], NULL);
- }else{
- pthread_join(tId[countProc - 1], NULL);
- countProc--;
- pthread_create(&tId[countProc], NULL, Process, filePath);
- countProc++;
- pthread_join(tId[countProc - 1], NULL);
- }
- }
- }
- d = readdir(dp);
- }
- stat(curPath,&buf);
- printf("Path = %s, Size = %ld, FileCount = %d, ProcNumb = %d, PID = %d\n", curPath, buf.st_size, fileCounter, countProc, getpid());
- countProc--;
- return NULL;
- }
- int main(__attribute__((unused)) int argc , char *argv[] ){
- maxProc = atol(argv[3]);
- pthread_t tid;
- findPath = argv[2];
- pthread_create(&tid,NULL,Process,realpath(argv[1], NULL));
- countProc++;
- pthread_join(tid,NULL);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement