help with getting pid!!

S

seema

Hi all,

I am new to perl programming, I have return a perl script to get the
pid of all my_app currently running on HP-UX box,

#!/usr/bin/perl

@process_array= `ps -ef | grep my_app | grep -v grep | awk '{print
$2}'`;

foreach $index (@process_array)
{
print $index, "\n";
}

It doesnt give the pid of my_app am I doing some thing wrong here??
Thanks in advance,
 
J

J. Gleixner

seema said:
Hi all,

I am new to perl programming, I have return a perl script to get the
pid of all my_app currently running on HP-UX box,

#!/usr/bin/perl

@process_array= `ps -ef | grep my_app | grep -v grep | awk '{print
$2}'`;

foreach $index (@process_array)
{
print $index, "\n";
}

It doesnt give the pid of my_app am I doing some thing wrong here??
Thanks in advance,

Well, what does it give you? Look at the output of "ps -ef" and
compare that with what you're printing and adjust as needed.
 
J

John W. Krahn

seema said:
Hi all,

I am new to perl programming, I have return a perl script to get the
pid of all my_app currently running on HP-UX box,

#!/usr/bin/perl

@process_array= `ps -ef | grep my_app | grep -v grep | awk '{print
$2}'`;

foreach $index (@process_array)
{
print $index, "\n";
}

It doesnt give the pid of my_app am I doing some thing wrong here??
Thanks in advance,

#!/usr/bin/perl
use warnings;
use strict;

my @process_array = `ps -C my_app` =~ /^\s*(\d+)/gm;

print map "$_\n", @process_array;




John
 
J

Jürgen Exner

seema said:
I am new to perl programming, I have return a perl script to get the
pid of all my_app currently running on HP-UX box,

#!/usr/bin/perl
@process_array= `ps -ef | grep my_app | grep -v grep | awk '{print
$2}'`;
foreach $index (@process_array)
{
print $index, "\n";
}

It doesnt give the pid of my_app am I doing some thing wrong here??

Well, your _Perl_ code doesn't do much but printing the content of the array
@process_array and that looks ok to me.
Maybe you can check what that awful external command does and what it prints
to STDOUT?

BTW: why do you use Perl at all if all you do is printing the output of a
shell command?

jue
 
X

xhoster

seema said:
Hi all,

I am new to perl programming, I have return a perl script to get the
pid of all my_app currently running on HP-UX box,

#!/usr/bin/perl

@process_array= `ps -ef | grep my_app | grep -v grep | awk '{print
$2}'`;


If you had turned on warnings, then Perl would have told you
(approximately) what the problem is. Perl is interpolating its own $2, so
what awk sees is not literally $2, but rather the value that was held in
Perl's variable named $2.

Xho
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top