How to determine full command with args given a pid (or port in use)

1

I've got this nice bash function for telling me the pid using a port:

using_port() {
  lsof -i:${1}
}

Output looks like this:

COMMAND   PID   USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
ruby    43988 gordon   9u   IPv4 0xecaac2af83bf0aa7      0t0  TCP *:hbci (LISTEN)

Is there a way to easily get the full command that was run, including the path and args? Bonus points for updating the example function above.

justingordon

Posted 2013-05-30T21:30:58.437

Reputation: 1 073

Answers

1

command_using_port() {
    ps -p $(lsof -i:$1 -Fp | cut -c 2-) -o args --no-headers
}

Consult relevant man pages for description of options (that's what I did!)

glenn jackman

Posted 2013-05-30T21:30:58.437

Reputation: 18 546

For some reason, if I have the command rails server running, I only get "rails" as the arg. I'd like to see all the args passed. – justingordon – 2013-05-31T04:59:16.577