Not sure how relevant it is, but we get a pid differently in drush_sitealias_get_envar_filename(). We should use similar techniques if it makes sense.