In my code I am trying to delete a directory having files and subdirectories using rm -rf .
While deleting I am getting the error message , "Directory not empty". This is happening because rm -rf recursively deletes the files inside the directory and comes out to delete the directory . Meanwhile, other thread creates new file in the same directory.
Is there a way to solve this issue. I want to force delete the directory and if possible lock the directory for writing and then delete it. I am using linux and C++.