I figured it out. Here's what I'm doing now - when I wait for clamd's socket to appear, I also check if the child process still exists using kill(0 => $pid). If it no longer exists, then it must have died somehow, and we have to stop the test.
Thanks Ovid and jm for allowing me to bounce thoughts around.
Full code sample:
my $pid = fork;
die "Fork failed" unless defined $pid;
if (!$pid) {
exec "eclamd -c clamav.conf";
die "Clamd failed to start: $!";
}
for (1..10) {
last if (-e "clamsock");
if (kill(0 => $pid) == 0) {
die "Clamd appears to have died";
}
sleep(1);
}
It's possible I can turn the for (1..10) into a while(1) now, but I think I'll leave it like that for now.