help with getting pid!!

Discussion in 'Perl Misc' started by seema, Jun 19, 2007.

  1. seema

    seema Guest

    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,
    seema, Jun 19, 2007
    #1
    1. Advertising

  2. seema

    J. Gleixner Guest

    seema wrote:
    > 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. Gleixner, Jun 19, 2007
    #2
    1. Advertising

  3. seema wrote:
    > 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
    --
    Perl isn't a toolbox, but a small machine shop where you
    can special-order certain sorts of tools at low cost and
    in short order. -- Larry Wall
    John W. Krahn, Jun 19, 2007
    #3
  4. seema wrote:
    > 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
    Jürgen Exner, Jun 19, 2007
    #4
  5. seema

    Guest

    seema <> wrote:
    > 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

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Jun 19, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harlin Seritt

    Getting PID for process

    Harlin Seritt, Apr 29, 2005, in forum: Python
    Replies:
    2
    Views:
    355
    runes
    Apr 29, 2005
  2. eldorado

    getting a process's PID

    eldorado, Dec 27, 2006, in forum: Python
    Replies:
    11
    Views:
    523
    Tom Plunket
    Dec 28, 2006
  3. srinivasan srinivas

    Getting pid of a remote process

    srinivasan srinivas, Aug 18, 2008, in forum: Python
    Replies:
    1
    Views:
    229
    Diez B. Roggisch
    Aug 18, 2008
  4. srinivasan srinivas

    Re: Getting pid of a remote process

    srinivasan srinivas, Aug 19, 2008, in forum: Python
    Replies:
    1
    Views:
    729
    Diez B. Roggisch
    Aug 19, 2008
  5. Marc Heiler

    Getting PID of external command

    Marc Heiler, Mar 12, 2007, in forum: Ruby
    Replies:
    3
    Views:
    124
    Jan Friedrich
    Mar 17, 2007
Loading...

Share This Page