Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

How do i obtain the PID of a program already running.

by Adityad (Initiate)
on Jun 29, 2000 at 19:05 UTC ( #20387=categorized question: print w/replies, xml ) Need Help??
Contributed by Adityad on Jun 29, 2000 at 19:05 UTC
Q&A  > programs and processes


How do i find out the PID of a program that is already running, outside my perl script. eg. suppose calc.exe is running and i want to find out its PID how, do i do that. Also what is the syntax for Ps.

Answer: How do i obtain the PID of a program already running.
contributed by QandAEditors

The options on ps vary greatly from one OS to another. Use your system's man command to find the syntax of ps for your os.

The Proc::ProcessTable module gives you a relatively OS independant way of getting and working with a process list. -- lhoward

Answer: How do i obtain the PID of a program already running.
contributed by QandAEditors

Your first question, how to find the process id for a process running completely independent of your perl script, you can use ps.

As for your second question, the syntax for ps can differ depending on which UNIX architecture you're on, which version of it, and even which version of ps is installed. A good place to start is by looking at the man page for ps.

What confuses me is that you as about ps, but you also mention calc.exe running. This sounds like a Windows app, not UNIX. There's no ps (without some toolkit) native to windows.

For windows, I can suggest either getting one of these toolkits (such as the Resource Kits), or using a perl module (a quick search for one didn't turn up anything, but there's probably one out there).

Hope that helps.

Update: Suggested by lhoward, Proc::ProcessTable is the perl module you're looking for.

Answer: How do i obtain the PID of a program already running.
contributed by QandAEditors

ps -C program_name

From the Chatterbox earlier today, you were wanting to kill all the apache PID's with Perl...

shell> ps -C httpd | perl -pe '($_)=/(\d+)/;`kill -9 $_`'
That should work as root



Please (register and) log in if you wish to add an answer

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (1)
    As of 2020-10-25 23:29 GMT
    Find Nodes?
      Voting Booth?
      My favourite web site is:

      Results (249 votes). Check out past polls.