Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to tell what current shell is in perl code 1

Status
Not open for further replies.

whn

Programmer
Oct 14, 2007
265
US
I wrote a very simple perl code (named tt.pl) like this:

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,
 
You could use ps -f

From the output choose the process whose PID is equal to the PPID of your perl.

hope this helps
 
Thank you, hoinz! Can not believe I forgot this.

Maybe I could blame NBA for this.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top