As an alternative to doing pidfiles, how about following the way that lxcapi_create does it with fcntl(fd, F_SETLKW? (see create_partial() and ongoing_create()? Then if the monitor exited without being able to clean up, we can detect it and clean up.