Skip to content

Comment on Show HN: Highlander – Stop Overlapping Python Cron Jobsparent

Comments

To address your concerns:

1. I assume that it's the same type of process because by default the PID file is being written to the current working directory of the script. If you'd like, you can specify a location yourself to ensure that each type of process is grouped on one PID file.

2. Out of curiosity, how would you go about doing this?

3. I think this would be really difficult to accomplish.

4. I agree if we could somehow figure out 2 or 3, that would be great.

1) As noted by Michael in a sibling comment - and I've had this happen in real life - a PID from a command which exited abnormally (and thus didn't clean up the file) can be picked up by another process, particularly on busy boxes. If your pid gets picked up by, say, an nginx worker, in which case your cron may never start again.

2) /proc/[pid]/stat column 14 - utime. Look for this to increment with every check.

3) An update function call from within the program itself - a particular count of a single location, or the lack of an update while (2) is updating could indicate an infinite loop.

The point for #1 is that PIDs are reused. Just because the cron job previously started a process with a PID 473 doesn't mean that PID 473 is that same process the next time the cron job comes around to check. It's entirely possible that the original process was finished or killed and a new process started with the same PID.

This is why I also store the creation time to avoid reused PIDs.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.