(Solved) How do I make flock ignore a nohup process?

Hi!

I've a cronjob that I don't want to be concurrent but it needs to leave a long-running process after it does it's job that I set up with a nohup command.

The deal is that once the script has setup the lock doesn't get released so any further calls to the script just get ignored.

Is there a better alternative/flag I'd use? I couldn't discern much from the flock or nohup man pages.

Solved: With bit more fiddling found the - u flag on the flock man page. You can unlock yourself at the very end of the script.

15 points · 7 comments · view on lemmy.world

7 Comments

hades@feddit.uk · 3 pts · 308d (1 reply)

Can you modify the script to release the lock after the process has started?

Gonzako@lemmy.world · 2 pts · 308d

Yes! I found the - u flag on flock and that got it working. Thanks for the attention anyway.

Frid0lin@feddit.org · 2 pts · 308d (4 replies)

Could you just save the pid of that cronjob in a file? (Assuming this cronjob calls bash script). Before the next run of the cronjob check if that process with that pid is still running? Hoping, I understand your problem correctly. You do not want to run the cronjob again until the first run finishes?

Gonzako@lemmy.world · 2 pts · 308d (3 replies)

Flock does this functionality, the deal is that it waited for the long-running process to end so it wouldn't release the lock after the script was done. Adding a line manually releasing it fixed it.

It's an auto-update script, you don't wanna start a new update while one is underway.

Frid0lin@feddit.org · 2 pts · 308d (2 replies)

Thanks for the update maybe I'm a bit oldschool and need to dig deeper "in the flock" ;-)

Gonzako@lemmy.world · 2 pts · 308d (1 reply)

sorry fLock it my phone doesn't like it and don't really know what the f stands for. but flock is a Linux command that let's you manage simple concurrency issues https://www.man7.org/linux/man-pages/man1/flock.1.html

Badabinski@kbin.earth · 2 pts · 307d

the f stands for file. The c manpage has some details on how it works: https://www.man7.org/linux/man-pages/man2/flock.2.html