red_draign has asked for the wisdom of the Perl Monks concerning the following question:
sub _getppid() {
my $ppid;
my $name;
if ($^O =~ /^MSWin32$/i) {
my $pid = $$;
my $machine = "\\\\.";
require Win32::OLE;
require Win32::OLE::Variant;
# WMI Win32_Process class
my $class = "winmgmts:{impersonationLevel=impersonate}$machine\\Root\\cimv2";
if (my $wmi = Win32::OLE-> GetObject($class)) {
my $inc = 0;
while ($inc < 3) {
my $proc = $wmi->Get(qq{Win32_Process.Handle="$pid"});
if ($proc) {
$ppid = $proc->{ParentProcessId} if ($proc->{ParentProcessId}!=0);
$name = $proc->{CommandLine} if ($proc->{ParentProcessId}!=0);
$pid = $ppid;
++$inc;
}
}
}
$name =~ s/cmd \/c ""(.*)" "/$1/;
}
else {
$ppid = getppid();
$name = `ps -o args -p $ppid`;
chomp($name);
$name = (split(/\n+/, $name))-1;
$name =~ s/\/bin\/ksh (.*)/$1/;
}
return ($ppid, $name);
}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: caller of perl script
by moritz (Cardinal) on Jun 11, 2010 at 14:12 UTC | |
by Anonymous Monk on Jun 11, 2010 at 15:26 UTC | |
by moritz (Cardinal) on Jun 11, 2010 at 16:11 UTC | |
by jdrago999 (Pilgrim) on Jun 11, 2010 at 16:58 UTC | |
by BrowserUk (Patriarch) on Jun 11, 2010 at 17:04 UTC | |
| |
by Anonymous Monk on Jun 16, 2010 at 00:16 UTC | |
|
Re: caller of perl script
by BrowserUk (Patriarch) on Jun 11, 2010 at 17:27 UTC | |
|
Re: caller of perl script
by ikegami (Patriarch) on Jun 11, 2010 at 19:24 UTC | |
|
Re: caller of perl script
by youwin (Beadle) on Jun 11, 2010 at 22:37 UTC | |
by BrowserUk (Patriarch) on Jun 12, 2010 at 05:00 UTC | |
|
Re: caller of perl script
by cdarke (Prior) on Jun 12, 2010 at 13:19 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |