From: Vikram K. <vk...@re...> - 2007-07-11 19:33:36
|
Here is something off the top of my head: Create a script file, eg "extract.sh" as follows ls -l targetfilenamehere | sed 's/[a-z]//g' | sed 's/[A-Z]//g' | sed 's/-//g' | sed 's/\.//g' | sed 's/ /\n/g' | sed '/^$/d' | head -2 | tail -1 > /tmp/targetsize.txt This should put the size of the file in bytes into /tmp/targetsize.txt After you are done with your fclose in the program, do a while loop as follows while(1) { /* Call the script */ system("./extract.sh"); /* Check the contents of /tmp/targetsize.txt */ /* Insert code to open /tmp/targetsize.txt and read the integer */ /* Check if the size is what you expect */ if( read_size == expected_size) { printf("\n Done."); exit(0); } else { sleep(1); } } If you don't know the expected size, you can merely save the previous size, and if the read_size is same as previous_size, you can "assume" that nothing changed in a second, and hence, "probably" the file writing work is done. It is dirty, but you should have it working in a few minutes Hope this helps Vikram On Wed, 11 Jul 2007, Joshua Hintze wrote: joshh>Date: Wed, 11 Jul 2007 13:03:56 -0600 joshh>From: Joshua Hintze <jo...@pr...> joshh>Reply-To: General mailing list for gumstix users. joshh> <gum...@li...> joshh>To: 'General mailing list for gumstix users.' joshh> <gum...@li...> joshh>Subject: [Gumstix-users] File finished writting joshh> joshh>Hey guys, joshh> joshh> joshh> joshh>I was wondering if there is some linux command or way to tell if a file has joshh>finished writing. Here is why I ask. I have a Verdex board with the USB host joshh>connected to a USB jump drive. In my C++ code I will write to a file handle joshh>that is opened on the mounted USB thumb drive and write about a 2 meg file joshh>to it. joshh> joshh> joshh> joshh>However, the write command (actually an mmap) finishes immediately and I joshh>fclose the file, but in reality the OS is still writing out to the USB. This joshh>is apparent when you try to unmount or stupidly yank the thumb drive out. joshh> joshh> joshh> joshh>So my question is..is there a way to determine if the file writing has joshh>finished? Especially some command I can run from within a program. joshh> joshh> joshh> joshh>Thanks, joshh> joshh> joshh> joshh>Josh joshh> joshh> joshh> joshh> |