While there is a potential race condition, it seems rare enough to avoid. My problem was not a race condition, but neglected to put my commandline code in a loop. Also deleted semaphore variables.