That's wrong. It suffers from a race condition.
+===============================+===============================+ | Process 1 | Process 2 | +===============================+===============================+ | open the status file | | T | read the status (status is 1) | | i +-------------------------------+-------------------------------+ m | | open the status file | e | | read the status (status is 1) | | | | write 2 to the status file | | | | proceed | | +-------------------------------+-------------------------------+ v | write 2 to the status file | | | proceed | | +===============================+===============================+
If you use flock, then it's just an extention of what the OP posted.
( Oops! Seems like tye posted something similar when I was writing this node. )
In reply to Re^2: Ensuring only one copy of a perl script is running at a time
by ikegami
in thread Ensuring only one copy of a perl script is running at a time
by eyepopslikeamosquito
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |