get PID in "lsof -i: 8080" command

Discussion in 'Java' started by ma_kiem, Jul 6, 2011.

  1. ma_kiem

    ma_kiem

    Joined:
    Jul 5, 2011
    Messages:
    2
    I have code:
    import java.io.IOException;
    import java.io.InputStream;

    public class ExecuteDOSCommand {
    public static void main(String[] args) {
    final String dosCommand = "lsof -i: 8080";
    try {
    final Process process = Runtime.getRuntime().exec(dosCommand);
    final InputStream in = process.getInputStream();
    int ch;
    while((ch = in.read()) != -1) {
    System.out.print((char)ch);
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }

    It's output:
    COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
    java 1234 root 123 IPv6 819768 TCP *:8080 (LISTEN)

    I want to get PID=1234, how do i do?:bowl::bowl::bowl::bowl:
    ma_kiem, Jul 6, 2011
    #1
    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. Sunil Menon
    Replies:
    2
    Views:
    546
    Sunil Menon
    Jul 27, 2003
  2. Ray5531
    Replies:
    8
    Views:
    805
    Ray5531
    Jun 22, 2005
  3. Joe Schmoe

    How to get PID of invoked COM object?

    Joe Schmoe, Nov 16, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    3,168
    Bruce Barker
    Nov 16, 2005
  4. g.willgoose@telluricresearch.com

    get pid of a nohup command in Python

    g.willgoose@telluricresearch.com, Feb 13, 2007, in forum: Python
    Replies:
    1
    Views:
    607
    Gabriel Genellina
    Feb 13, 2007
  5. Marc Heiler

    Getting PID of external command

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

Share This Page