get PID in "lsof -i: 8080" command

Joined
Jul 5, 2011
Messages
2
Reaction score
0
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:
 

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

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top