LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-07-2005, 03:34 AM   #1
rajsun
Member
 
Registered: Mar 2005
Posts: 61

Rep: Reputation: 15
How to perform atomic copy of file through cp command.....


Hi all,
I m copying files from one directory to another directory from my C code. I have used system("cp -p source destination") function in my code to perform the file copy.

Now mean while, when the copying of file is in progress, through another script I m removing the files from source folder. Because of that my programe is failing.

I want to restrict the removal of files while my code is in execution. Once the the file copy is done then one can remove the file.

I want to know whether any mechanism is there to enforce atomicity while copying the files, i.e. while file copy is in progress then no othere process can delete the file.


If any body has any idea how to acomplish this task then please help me out....

[Note :: I m using C in Suse Linux.]

Thanking u all
With Regard
RajSun.

Last edited by rajsun; 12-07-2005 at 03:35 AM.
 
Old 12-07-2005, 05:54 AM   #2
dsumedh
LQ Newbie
 
Registered: Dec 2005
Distribution: Slackware, Mandrake
Posts: 15

Rep: Reputation: 0
In your program, make 2 threads of execution.
thread 1: do ur copy stuff
thread 2: (parent) - wait for thread 1 to complete..then call your script that does the file removal.

In case i got your scenario wrong, I apologise..do re-phrase the scenario in that case..
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't perform root command by using Sudo acbenny Linux - General 6 05-07-2008 08:19 PM
Given a URL how to grab a copy of the file from a command prompt ? Mike Davies Linux - General 2 07-16-2005 11:46 AM
How do you copy and paste a file from a command prompt? thenewguy05 Linux - Newbie 6 07-13-2004 03:41 PM
Copy A File Off A CD To The Hard Drive In Command Line nickae77 Linux - Newbie 4 05-21-2004 04:38 AM
command line CDR / copy file rioguia Linux - Newbie 4 10-05-2002 04:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration