in my php script which runs as a cron job, I have
foreach($sites as $site)
exec('./wkhtmltoimage-amd64 ' . $site . ' somefile.png');
exec('./zopflipng -y somefile.png somefile.png');
to generate screenshots monthly for each site.
Now, this cron job runs once a month, and in the unlikely event that someone wanted to delete the image while this job ran, I'm not too sure what would happen. Would the image just not get deleted since it's in use? If that's the case, then how do I make it delete after it's no longer in use?
I've thought of a solution where I could just kill the process, but I am unsure of the outcome too. If I use
lsof -t somefile.png
that will give me the PID of the process. With that, I can kill the process within the delete function of the site using
exec('lsof -t somefile.png | kill -15');
After killing, will the original script near the top of this post still go on? Will the job be canceled? Does the cron job error out? I'd like for it to just be able to move on to the next site.