make for_each_process change into current path

remove duplication and cuts down on chdir operations
factor out testing pid_files into separate function