in reply to Play random music

When I'm writing a daemon will drop a file ususally based on the PID $$ and then inside the loop test for the existence of the file and exit if the file is deleted:

open PID,">$$" or die $@;
close PID;

while (-e $$) {
do_good();
}