I have a big pcap file, from which I filter out some packets with tshark, save them in new pcap files and put the filenames of the new pcap files in an array called "filename_array". At the end I delete all the files which are saved in the filename_array. But one file from this array is still open when the delete process starts and due to that the error "text file busy" occurs.
So, a solution would be, to check, if all files of the array are closed. If it's true, I can delete all of them. How can I do this?
You can check for exception while reading or deleting the file and handle it.
try:
with open('filename'):
#include the file to be deleted in array
except IOError:
# skip the file
A better way is use 'lsof' to list all opened files in system
https://www.ibm.com/developerworks/aix/library/au-lsof.html
https://www.thegeekstuff.com/2012/08/lsof-command-examples
https://alvinalexander.com/blog/post/linux-unix/linux-lsof-command
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.