in reply to How Was My Script Run?
On Windows it is not so easy. For some reason getppid is not implemented although there are Win32 API calls which will give details of the parent process based around CreateToolhelp32Snapshot() API.use warnings; use strict; my $ppid = getppid(); open (my $cmdfh, '<', "/proc/$ppid/cmdline") or die "Unable to open pp +id cmdline: $!"; my $cmdline = <$cmdfh>; close $cmdfh; if ($cmdline =~ /bash|ksh|csh/) { print "Started by a shell\n"; } elsif ($cmdline =~ /perl/) { print "Perl is the daddy\n"; } else { print "I was created by: $cmdline\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How Was My Script Run?
by Anonymous Monk on Mar 15, 2011 at 10:56 UTC | |
by HalNineThousand (Beadle) on Mar 15, 2011 at 16:11 UTC | |
by Anonymous Monk on Mar 15, 2011 at 16:18 UTC | |
|
Re^2: How Was My Script Run?
by TomDLux (Vicar) on Mar 15, 2011 at 19:06 UTC |