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

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...
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”...
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...
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; }
(using C in a Linux environment and the POSIX pthreads library) Write a program named Sort.c...
(using C in a Linux environment and the POSIX pthreads library) Write a program named Sort.c that accepts a list of numbers from the user. There are two threads: Main thread waits for the numbers to be entered by the user and for the second thread to finish sorting. It then asks user whether there are more lists or not. It will do this until the user indicates there are no more lists to be entered, at which point it...
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++...
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++ Rules: -Use fork(), exec(), wait(), and exit() _______________________________________________________________________________________________________________________________________________ -A line of input represents a token group. -Each token group will result in the shell forking a new process and then executing the process. e.g. cat –n myfile.txt // a token group -Every token group must begin with a word that is called the command(see example above). The words immediately following a command are calledarguments(e.g....
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++...
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++ Rules: -Use fork(), exec(), wait(), and exit() _______________________________________________________________________________________________________________________________________________ -A line of input represents a token group. -Each token group will result in the shell forking a new process and then executing the process. e.g. cat –n myfile.txt // a token group -Every token group must begin with a word that is called the command(see example above). The words immediately following a command are calledarguments(e.g....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT