You're going to have check the parent folder and contents and pause until there are no more changes. Two ways of doing that would be to get the size of the entire contents of the parent folder every second until the size no longer changes using du
, or to look for open files with the parent folder as part of their path using lsof
.
For lsof
, probably the most reliable method, see @peternlewis's post here and the follow-on discussion.