Determine parent shell from perl -


from perl know name (and possibly path) of shell started perl process.

$env{shell} not give (it gives login shell - current perl process might started different shell).

the best answer have found far is: http://www.perlmonks.org/?node_id=556926 deals terribly different platforms (the output of 'ps' differs wildly platform platform).

i tried looking @ %env, contains exported variables.

so there better way?

background

this used gnu parallel: every job started through shell. give least surprise user, shell should same shell gnu parallel started from. way tcsh-user able run tcsh commands gnu parallel , same bash/zsh/*sh user.

currently $shell used, gives login shell , not current shell surprising users, run different shell login shell. can cause problems if gnu parallel used in script written tcsh-user, run bash-user.

if gnu parallel not started shell, default $shell (same now).

how this:

#!/usr/bin/env perl  use strict; use warnings; use feature 'say';  use proc::processtable;  $t = proc::processtable->new;  $current_pid = $$; @parents;  # loop on process table until we've found parents perl pid # init (process id 1) while ($current_pid != 1) {     $process (@{ $t->table }) {         if ($process->pid == $current_pid) {             push @parents, $process;             $current_pid = $process->ppid;         }     } }  # loop on parents we've found , looks # shell command $process (@parents) {     $cmd = $process->cmndline;      if ($cmd =~ m/sh$/) {         $cmd;         last;     } } 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -