Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search by port #19

Closed
JakubKahovec opened this issue Mar 5, 2017 · 23 comments
Closed

Search by port #19

JakubKahovec opened this issue Mar 5, 2017 · 23 comments

Comments

@JakubKahovec
Copy link

It'd be great if it's possible to also search by a port being open by a process

@sindresorhus
Copy link
Owner

I like the idea. How do you imagine it would work? What would it look like?

@JakubKahovec
Copy link
Author

Thanks ;-) It might be something like you run fkill-cli and next to the Running processes there'd be in brackets by what you're searching and you can switch it by a shortcut.

Search running processes (by Name/Pid/Port) :

@SamVerschueren
Copy link
Contributor

I see two options

Flags

fkill -p or fkill --port could start the tool in port mode where searching will match the port.

Automatic parsing

Just run fkill and if the input looks like a port (numeric, between 0 and 65535, ...) use the port is filter strategy.

@sindresorhus
Copy link
Owner

sindresorhus commented Mar 7, 2017

I think automatic parsing would be nicer, but one downside (?) is that you would miss the ability browse through ports. Not sure that's something people would need though.

@SamVerschueren
Copy link
Contributor

What do you mean with browse through ports?

@sindresorhus
Copy link
Owner

@SamVerschueren I mean, if you just want to see what apps are using which ports.

@dnbkr
Copy link
Contributor

dnbkr commented Mar 13, 2017

You could use automatic parsing for finding and killing (when you know the port number connected to the proc you want to kill) and then also have a 'ports' subcommand, maybe?

fkill 8080
# searches for procs using port 8080, the same what automatic searching currently works (maybe, if there's a proc owning the port it jumps to the top of the search, and proc names / args containing the port by coincidence come below it)

fkill ports
# displays scrollable list of procs using ports, with the ports in their own column along side pids 

Sidenote; https://www.npmjs.com/package/node-netstat may be good for this.

@pirate
Copy link

pirate commented Mar 14, 2017

Careful, people will assume the first arg to fkill is a PID or process name, not a port, and they can conflict. Probably better to have fkill --port 8080 or fkill ports then search with port:8080 or something like that.

You can find all port-> process mappings with netstat -tan or lsof +c 0 -i:8080.

@dnbkr
Copy link
Contributor

dnbkr commented Mar 15, 2017

@sindresorhus, @pirate how do you feel about:

fkill ports  # interactive autocomplete search based on port number
fkill ports 8080  # kill the process currently using port 8080
fkill ports 8080 8081 8082  # kill the processes currently using ports 8080-2

using a ports subcommand will limit any confusion between port number and pid.

@pirate
Copy link

pirate commented Mar 15, 2017

I'd rather a flag than a subcommand, as the word ports itself could be a process name, and that leads to ambiguity with parsing the first argument. How about --port?

@dnbkr
Copy link
Contributor

dnbkr commented Mar 16, 2017

yep, that makes sense - --port works for me.

fkill --port  # interactive autocomplete search based on port number
fkill 8080 --port  # kill the process currently using port 8080
fkill -p 8080 8081 8082  # kill the processes currently using ports 8080-2

@pirate
Copy link

pirate commented Mar 16, 2017

👍 for your second example, I think only allowing fkill --port 8080 makes more sense, (otherwise you run into the pid vs port ambiguity problem).

@dnbkr
Copy link
Contributor

dnbkr commented Mar 16, 2017

do you mean fkill --port 8080 vs fkill 8080 --port ? Because i think flags should be treated as non-positional; so if -p or --port is present then positional arg 1-n will always be treated as ports, not pids.

@pirate
Copy link

pirate commented Mar 16, 2017

Up to you, I personally favor stricter argument parsing, but it's your call @sindresorhus & @coffeedoughnuts ;)

@sindresorhus
Copy link
Owner

do you mean fkill --port 8080 vs fkill 8080 --port ?

The argument parser we use supports both, but we should only document fkill 8080 --port as it's the clearest. In fkill --port 8080 it could both mean it's the value of --port or the first argument.

@sindresorhus
Copy link
Owner

I'm ok with a --port flag.

@YurySolovyov
Copy link

how about searching by port after user typed colon : ?
$ fkill
user types:
:8080
shows list of apps on 8080

@pirate
Copy link

pirate commented Apr 4, 2017 via email

@sindresorhus
Copy link
Owner

Yeah, I would be fine with that too.

I assume it would be:

$ fkill :8080

And

$ fkill
? Running processes: :8080

Is everyone good with this?

// @SamVerschueren @coffeedoughnuts @MarkTiedemann @alextes

@MarkTiedemann
Copy link

LGTM.

@dnbkr
Copy link
Contributor

dnbkr commented May 2, 2017

Yep, :PORT seems good to me;

@sindresorhus
Copy link
Owner

sindresorhus commented May 8, 2017

Cool. Let's go with that then. Pull request welcome :)

@sindresorhus
Copy link
Owner

sindresorhus commented Feb 1, 2018

Marking as "help wanted" again. See #27 for previous attempt.

kevva added a commit to sindresorhus/fkill that referenced this issue Feb 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants