On Unix, there are three common ways to solve this.
in reply to Cron Jobs That Run For Too Long
The first way is to have a lockfile that's always around. When your script starts, it tries to lock that file with flock; if it's already locked it exits, otherwise it does its work. The OS will automatically remove the lock when the process exits, even if it crashes or is killed.
The second way is to write the PID of the process into the lockfile. Then when another copy starts up, it checks if the lockfile exists, and if so it reads the PID and verifies that that PID is still running and is actually itself. If it finds that the process is no longer running, it just creates a new lock file and goes on. When the process finishes it removes the lockfile.
The third way is to get a list of all processes, and see if any of those are executing that script. If so, exit.
I generally favor the first of these, because it's easy and efficient.