Posts: 107
Joined: Sun Jan 18, 2015 1:31 pm

cp -r Rpi2 hangup?

Wed Sep 23, 2015 1:28 pm

My Python script uses: os.system("cp -r /media/A/DATA /media/B")
I am copying the folder "DATA" located on the "A" USB flash drive to the "B" USB flash drive. The "DATA" folder contains .csv files. This seems to work as expected as the folder and all of its contents are copied to the "B" flash drive. The problem comes in whenever my script tries to access and edit one of the .csv file on "A" drive AFTER I have copied the data to "B" drive. The program hangs and runs VERY slow and sometimes locks up all together. Is there something more to "cp -r" that I should be doing after the copy is finished to close the drive or free resources?

Raspbian OS
default clock speed

Thank you,

Posts: 14436
Joined: Tue Jul 17, 2012 3:02 pm

Re: cp -r Rpi2 hangup?

Wed Sep 23, 2015 3:57 pm


I presume that if you do that "cp -r /media/A/DATA /media/B" command by hand from the command line and then look at your files with an editor or just "less" then they are as you expect.
Memory in C++ is a leaky abstraction .

User avatar
Posts: 3135
Joined: Tue Oct 11, 2011 8:38 pm

Re: cp -r Rpi2 hangup?

Wed Sep 23, 2015 4:58 pm

"cp" has done its job when it has read the data from one place and told the kernel to write them to the other. By this point you can see and access the files in the new location, but the kernel has not necessarily finished committing the data to the physical device. It will hold them in RAM in order to write them out in the most efficient way. This could take thirty seconds or more.

When there are a lot of I/O operations still in progress, other accesses may be queued and could take noticeably longer than usual. Programs can block for a few seconds at a time because they are unable to proceed until their read accesses complete.

The command "sync" will wait for all outstanding writes to finish. This is no better, and may be less efficient, than just being patient.

If your program is "hanging" or "locking up" permanently, then that is a different problem.

Return to “General discussion”