I wrote a very simple perl code (named tt.pl) like this:
And the output:
So, apparently I can not use 'ps | grep $$' in my perl code to find out under which shell I am running my perl code.
Is there a way in perl to find out under which shell my perl code is invoked?
Thanks,
Code:
my $ps = `ps | grep -v grep`;
[COLOR=blue][b]#my $ps = `ps | grep $$ | grep -v grep`;[/b][/color]
print "$ps";
print "current pid: $$\n";
And the output:
Code:
[COLOR=blue]% tt.pl[/color]
PID TTY TIME CMD
[b] 1126 pts/73 00:00:00 bash[/b]
[COLOR=red]15461 pts/73 00:00:00 tt.pl[/color]
15462 pts/73 00:00:00 sh
15463 pts/73 00:00:00 ps
current pid: [COLOR=red]15461[/color]
%[COLOR=blue] ps | grep $$[/color]
[b] 1126 pts/73 00:00:00 bash[/b]
So, apparently I can not use 'ps | grep $$' in my perl code to find out under which shell I am running my perl code.
Is there a way in perl to find out under which shell my perl code is invoked?
Thanks,