My program does 2 functions i.e.
a) It creates text files
b) The text files gets copied to some other locations.

The program is as below:

$n=5; #Count of files to be created. 
for($i=0;$i<=$n;$i++) {
print "\n$i file is getting created \n";
open(FH,">file_$i.txt") || warn "cannot create a file\n";
print FH "count of file: $i\n"; #Sample data to be written. just an example.
system("cp file_$i.txt /home/backup/testing/files")
close FH;

Is it possible to make the "CP" command i.e. copying the files from current working directory to other directory
to be independent of the main code?

The first file gets created and then the CP command gets called and file gets transfered again the next file
gets created and CP command is called and so on. As a sample data i have given the count to be written what if
there is huge amount of data (around 1 MB) to be written and transferred. It takes quite amount of time.

How can i make the file copying as an indepenent process?
Say 1..10 file1 gets created ---- cp is called as an independent/background process
file 2 gets created but cp will be called in parallel not as a dependent process
file4... etc..

File creation should not wait for the CP command process both should be in parallel?

How can i do it in Perl?


Hi amithlaxman!

Have you looked into the fork() function?


No i am not clear with fork() function?


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.