1

如何从 Perl 脚本中确定它是通过 SGE 运行还是从命令行本地运行?

4

3 回答 3

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 运行。

于 2011-03-14T15:50:31.467 回答
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";
}
于 2012-08-30T16:32:58.357 回答
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 版本,名称可能会有所不同。

于 2011-08-31T05:10:28.557 回答