Question

In: Computer Science

C program for copying data from one directory to another using multi threading for linux using...

C program for copying data from one directory to another using multi threading for linux using command line arrangement.

Program will take two arguments:

1: Source

2: Destination

it will copy all the files from source to destination recursively

Deadline: 4 hours from now.

Solutions

Expert Solution

hello ,

This is function for copy data from one directory to another

#include "snippet.h"
void <miss_class_def>::cpyAllFiles(dirInfo *s, dirInfo *t)
{
if (dir::exists(t->n) == false)
{
dir::Createdir(t->n);
}
foreach(FileInfo p in s->GetFiles())
{
if (p::dir->n == rootdir)
{
p->cpyTo(Path::Combine(t->ToString(), p->n), true);
FileSize += p->Length;
    }
}
// cpy each subdir using recursion.
foreach(dirInfo disSubDir in s->GetDir())
{
dirInfo *nexttSubDir = t->CreateSubdir(disSubDir->n);
//Thr t = new Thr(delegate() { Filecpy(disSubDir, nexttSubDir); });
//t.Start();
ThreadCon *objCon = new ThreadConr(disSubDir, nexttSubDir);
ThreadStart tempVar(objCon->ThreadFunc);
Thread *objThr = new Thr(&tempVar);
objThr->Start();
CpyAllFiles(disSubDir, nexttSubDir);
delete objThr;
delete objConr;
}
}
return 0;
}

And this is the thread container class :

#include "snippet.h"
ThreadCon::ThreadCon(dirInfo *objs, dirInfo *objt)
{
   tsource = objs;
   ttarget = objt;
}
void ThreadCon::ThreadFunc()
{
   foreach(FileInfo p in ts->GetFiles())
{

p->CpyTo(Path::Combine(ttarget->ToString(), p->n), true);
   }

}


Related Solutions

Can anyone who is knowledgable with multi-threading take a look at the following c++ program posted...
Can anyone who is knowledgable with multi-threading take a look at the following c++ program posted below and take a swing at making it multi-threaded (and if possible please use C++ 2011 standard threading). Its only one part of the overall program, so there wont be anything to compile/test but if you could take a crack at it that would be great. Even if it doesnt work when I test your program, ill still give credit/like since then ill at...
IN C LANGUAGE: Write a multi-threaded Linux program that synchronizes it's threads to write to a...
IN C LANGUAGE: Write a multi-threaded Linux program that synchronizes it's threads to write to a file without the file becoming corrupted. To do this, your program will create three threads which write strings to the same file. Each thread will randomly write a selection of strings to the file at random intervals. When finished, the file will contain all the strings written correctly to the file. You may use mutexes, semaphores, or a monitor your write on your own....
Systems Programming - File Operations in Linux using C Preventing copying the same file What does...
Systems Programming - File Operations in Linux using C Preventing copying the same file What does the standard cp do if you try to copy a file onto itself? $ cp file1 file1 cp: 'file1' and 'file1' are the same file Modify cp1.c to handle the situation and include comments. /** * @file cp1.c * @brief Uses read and write with tunable buffer size * usage: cp1 src dest */ #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <stdlib.h> #define BUFFERSIZE...
In Linux Terminal 1. Give a command using find to search from the root directory the...
In Linux Terminal 1. Give a command using find to search from the root directory the file program.f and redirect any errors to the file myerrors.txt 2. Give a command for finding files having the letters index as the beginning of the file name and located in your home directory (provide the absolute path) 3. Give a command for finding within a directory called /mp3collection, only those mp3 files that have a size less than 5000 Kilobytes (< 5MB). 4....
This program is a simple version of the linux shell using execvp by forking using C...
This program is a simple version of the linux shell using execvp by forking using C Currently this program of the shell assumes user enters no spaces before and no extra spaces between strings. Using exec, an executable binary file (eg: a.out) can be converted into a process. An example of using exec is implementing a shell program or a command interpreter. A shell program takes user commands and executes them. int execvp(const char *file, char *const argv[]); Same as...
Write a program in c++ that maintains a telephone directory. The Telephone directory keeps records of...
Write a program in c++ that maintains a telephone directory. The Telephone directory keeps records of people’s names and the corresponding phone numbers. The program should read a transaction file and report the result into an output file. The transaction file can include commands such as “Add”, “Delete”, “Display”, and “Update”, and “Search”. Each command is written in one line with a few other information. The “Display” Command should simply display everyone in the directory on the screen The “Add”...
The C++ program below simply copies the contents of one file to another file using standard...
The C++ program below simply copies the contents of one file to another file using standard in and standard out. Do a line-by-line conversion of the complete program into a closely equivalent C program that produces the same output given the same input. Note that the underscores are used solely to force indentation in Canvas. #include using namespace std; int main(void) { char symbol; cin.get(symbol); while (!cin.eof()) ___ { ___ cout.put(symbol); ___ cin.get(symbol); ___ } return 0; }
please write in c using linux or unix Write a program that will simulate non -...
please write in c using linux or unix Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally 10 jobs) and...
Please write in C using linux or unix. Write a program that will simulate non -...
Please write in C using linux or unix. Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally 10 jobs) and...
Lab – Linux Fundamentals Instructions: Using Kali Linux, the Windows Linux Sub-System, or another Debian based...
Lab – Linux Fundamentals Instructions: Using Kali Linux, the Windows Linux Sub-System, or another Debian based Linux distribution, perform the following tasks based on the Linux Fundamentals lecture. For this lab, take screenshots for all major steps completed to illustrate that each task was successfully completed (the same method as would be used for other labs). 9. Display your current directory in the terminal 10. Display your current directories contents including the inode value and permissions for each file and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT