I'm using scripted SSH access to launch a script on a remote server. I decided to break the remote scripts into two components. One script will do the heavy work, data collection, etc. The other script that's accessed via SSH will simply cat the collected results file. I needed a way to keep the two scripts from bumping into each other as each will either be reading or writing to the same remote data file.
After some experimentation, the following is what I came up with and is roughly equivalent at the beginning of each script. I found that without the match against a non-numeric value, the while loop would continue on...even if the other process had since exited and also when stating while($pid > 0). What am I missing? Thanks in advance for your insights and suggestions for improvement are also welcome.
#!/usr/bin/perl -w # # cat data obtained from collector script use strict; my $pid = `pgrep -f _collectDataScript.pl`; if ($pid) { while($pid) { print "Waiting for process $pid"; sleep(10); my $pid = `pgrep -f _collectDataScript.pl`; if ($pid !~ m/\d+/) { print "process id is non-numeric\n"; last; } } } print "process finished...do something\n";
In reply to process management by semio
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |