如何从Perl脚本确定它是通过SGE运行还是从命令行本地运行?
答案 0 :(得分:4)
来自http://www.cbi.utsa.edu/sge_tutorial:
When a Sun Grid Engine job is run, a number of variables are preset into the
job’s script environment, as listed below.
SGE_ROOT - The Sun Grid Engine root directory as set for sge_execd before
start-up or the default /usr/SGE
SGE_CELL - The Sun Grid Engine cell in which the job executes
SGE_JOB_SPOOL_DIR - The directory used by sge_shepherd(8) to store jobrelated
data during job execution
...
...
检查%ENV是否应该告诉您它是否通过SGE运行。
答案 1 :(得分:0)
您可以尝试这样的事情:
use Proc::ProcessTable;
my $running_under_sge = 0;
my $ppid = getppid();
my $t = new Proc::ProcessTable;
foreach my $p (@{$t->table}) {
if ($p->pid == $ppid) {
if ($p->cmdline =~ m/sge_shepherd/) {
$running_under_sge++;
last;
}
}
}
这可以通过检查程序的父进程来实现。如果父进程是sge_shepherd,那么它是由SGE exec守护进程启动的。根据您使用的Grid Engine版本,名称可能不同。
答案 2 :(得分:0)
jlp提供的脚本是一种彻底的检查方式,是我推荐的方法。但是,如果您只想快速声明,请检查环境是否具有SGE作业ID。见下文。
#!/usr/bin/perl
use strict;
my $job_id = $ENV{JOB_ID};
if ($job_id > 0) {
print "Is and SGE job";
} else {
print "Is NOT and SGE job";
}