Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm building an OSX app and use the screencapture command to grab a screenshot and write it to disk:

screencapture -mT0 ~/screenshot.png

Can I, if I'm not running a UNIX commands in the background, expect the file to be completely output when the command has been executed and I have received an exit status?

share|improve this question
Why do you need to ensure that it has been written to disk? (That is, assuming spinning platter hard drives for a moment, the magnetic field on the storage platter has been updated to reflect the new data.) Particularly for something as trivial as a screenshot, I fail to see the underlying use case. – Michael Kjörling Nov 26 '12 at 10:14
Because I want to open and manipulate that image in my app. – Sebastian Nov 26 '12 at 12:07
Then you don't need to ensure that the file has been written to disk, just that it's been output by the tool creating it. Thus, the question boils down to does screencapture finish writing its output file before exiting?, to which I believe the answer would be yes. (It'd require the tool to go well out of its way to not finish writing to its output file(s) before exiting.) Let the OS deal with caching and whatnot, and don't worry about that part. – Michael Kjörling Nov 26 '12 at 12:09

There are always buffers, so when the command returns, the file may not have been written to disk. All applications will see the file at this point, but if your system crashes or loses power, the file may not be present or may not be complete after you reboot.

You can run sync afterwards to flush all file system buffers but then there is a chance that the changes will be only in the disk buffer and not yet written to the disk itself.

share|improve this answer
...and of course, even if you sync a network share, that doesn't necessarily mean that the backing store has done anything in particular with your write. – Michael Kjörling Nov 26 '12 at 10:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.